d*******o 发帖数: 493 | 1 If the question is 'which method is the best in merging efficiently ',
everybody knows: Hash > Array= Proc format>Proc SQL >sort-sort-merge.
No doubt about it.
However, flyerr的问题是" data step v.s. Proc sql in creating new
variables".
Such as:
/××××××××××××××××××××××××××××××××××××××××/
PROC SQL;
CREATE table one AS
SELECT
CASE WHEN age=11 THEN 'pig'
WHEN sex='F' THEN 'monkey'
ELSE 'cat'
END
AS an... 阅读全帖 |
|
h******e 发帖数: 1791 | 2 在从sashelp.options里取data是出现的,但这个error似乎不影响结果。请问该如何除
去? |
|
o**********a 发帖数: 330 | 3 The following SAS program is submitted:
%macro COLS1;
Name Age;
%mend;
%macro COLS2;
Height Weight;
%mend;
proc print data=SASHELP.CLASS;
[_insert_VAR_statement_here_]
run;
Which VAR statement successfully completes
the program to produce a report containing
four variables?
A.
var %COLS1 %COLS2;
B.
var %COLS1-%COLS2;
C.
var %COLS1 Weight Height;
D.
var Weight Height %COLS1;
答案是d,一点思路都没有 |
|
P****D 发帖数: 11146 | 4 ……出这题的人有毛病吧……不愿自己给自己找麻烦的正常人肯定会这样写啊:
%macro COLS1;
Name Age
%mend;
%macro COLS2;
Height Weight
%mend;
proc print data=SASHELP.CLASS;
var %COLS2 %COLS1;
run; |
|
a********s 发帖数: 188 | 5 There are few different methods to put multigraphs on one page. The idea is
to generate the graphs first and then use PROC GREPLAY. Below is a simple
sample code to do this. I ever used another more flexible way to generate
graphs, but could not find the code, and also forgot how to do so ...
data a;
do i=1 to 100;
x = rannor(10);
y= rannor(4)+1;
z = rannor(3)+2;
w = rannor(5) + 3;
output;
end;
run;
proc gchart data =a;
pie x/name="pie1";
run;
quit;
proc gchart data =a;
pie ... 阅读全帖 |
|
t******o 发帖数: 27 | 6 有次不小心人为直接modify了vmacro里的内容,之后vmacro好像被lock住了,再也不能
自动记录更新macro variable的信息。关机重起也没有用。
有人知道是什么原因吗?谢谢! |
|
s******r 发帖数: 1524 | 7 little idea. If lock, try to search *.lck and delete it. |
|
t******o 发帖数: 27 | 8 试着search了一下没找到跟sas相关的.lck file。其实说lock也不准,现在我的vmacro
可以象普通dataset那样操作,比如删
除记录什么的,但是它不再automatically update了 :( |
|
s******y 发帖数: 352 | 9 给几个包子吧。
data class;
if 0 then set sashelp.class;
do i=1 to 10;output;
end;
stop;
run;
proc format;
value allmiss ._-.z=. other=1;
value $allmiss ' '=' ' other='1';
run;
ods select nlevels;
ods output nlevels=nlevels(keep=TableVar NNonMissLevels where=(
NNonMissLevels=0));
proc freq levels;
format _character_ $allmiss. _numeric_ allmiss.;
run;
ods output close; |
|
d*******o 发帖数: 493 | 10 我猜1。Proc SQL的第一步是判断有没有equijoin,如果不是才会用step loop形成
Cartesian product。所以normalize database才这么重要。
可以看下面这个例子里面log的执行方案,2比1复杂的多。
data a b;
set sashelp.class;
rename name = id;
run;
proc sql _method;
select a.* from a, b
where a. id =b.id;
quit;
proc sql _method;
select a.* from a, b
where a.id in
(select distinct id from b);
quit; |
|
k*******a 发帖数: 772 | 11 试试这个办法
1. 通过sashelp.vcolumn 这个view, 找出你的data里面所有 format 不为空的数值变量的
变量名和format,然后分别把他们存为 macro variable
2.读你的data, 对每个macro里面的variable,用 put转换为对应的format后看是不是
'NA' |
|
k*******a 发帖数: 772 | 12 试试这个macro, 他把你所有数值型变量转化为对应的format,如果这个obs有至少一个'NA',
那么就设
置flag=1,否者flag=0
%macro flag(lib=, data=, out=);
proc sql;
select name, format, count(*) into
:var separated by ' ', :fmt separated by ' ', :n
from sashelp.vcolumn
where upcase(libname)=upcase("&lib") and
upcase(memname)=upcase("&data") and
type='num' and
format ne '';
quit;
data &out;
set &lib..&data;
flag=0;
%do i=1 %to &n;
if put(%scan(&var,&i), %scan(&fmt, &i, "' '")) = 'NA'
... 阅读全帖 |
|
z**********i 发帖数: 12276 | 13 找到了,分享一下吧.
I randomly found a jpg file online and saved it in the folder. “Proc print
” part could be replaced by your purpose.
ods escapechar='^';
ods listing close;
options nodate number;
ods rtf file="example.rtf";
title '^S={preimage="S:\christmaspartyatthevfw014.jpg"} ';
proc print data=sashelp.class;
run;
ods rtf close; |
|
k*******a 发帖数: 772 | 14 写了隔macro你试试看
%macro rename(lib=,data=);
proc sql;
select strip(name)||'='||compress(name,'_') into :rename separated by ' '
from sashelp.vcolumn
where upcase(libname)=upcase("&lib") and upcase(memname)=upcase("&data");
quit;
data new;
set &lib..&data;
rename &rename;
run;
%mend; |
|
k*****u 发帖数: 1688 | 15 adv都是sas自带的data,大部分在sashelp 和 sasuser两个里面
sas下面,点击help,再点击geting started with sas software,就会加载进去
然后你就可以看到你要的data了 |
|
p******d 发帖数: 1120 | 16 94. The following SAS program is submitted:
%macro location(country);
proc sql ;
select 'sales', * into: dept from sashelp.class;
quit;
%put _global_;
%mend;
%let company =ABC;
%location(US)
Which macro variable(s) is/are written to the SAS log?
A.DEPT only
B.COMPANY only
C.COMPANY and DEPT only
D.COMPANY, COUNTRY and DEPT
为什么不是C?我记得 select into 也是创建全局变量的呀。
谢谢。 |
|
d******9 发帖数: 404 | 17 Use dictionary or SAS Help dataset, for example:
proc sql;
create table Z as
select *
from sashelp.vmember
where upcase(libname)='WORK';
quit; |
|
d******9 发帖数: 404 | 18 Use Proc Sort and data step.
proc sort data= sashelp.air out=B;
by air;
run;
data C;
set B NOBS=N;
by air;
if _N_ LE N*0.3 then group=1;
else if _N_ LE N*0.7 then group=2;
else group=3;
run;
proc freq data=C nlevels;
tables group/missing;
run; |
|
z**********i 发帖数: 12276 | 19 ods escapechar='^';
ods listing close;
options nodate number;
ods rtf file="example.rtf";
title '^S={preimage=" S:\banner9b.jpg"} ';
proc print data=sashelp.class;
run;
ods rtf close;
I think you could replace proc print by proc report. |
|
d******9 发帖数: 404 | 20 Or use macro to do it. Below codes works well, tested with few sample
datasets.
options mprint symbolgen;
data A_201201;
A=225;
run;
data A_201207;
A=226;
run;
data A_201205;
A=338;
run;
data R_201207;
A=338;
run;
data B_201279;
A=551;
run;
proc sql;
select memname into : tables separated by ' '
from sashelp.vtable
where libname='WORK' and upcase(substr(memname, 1,1))='A';
quit;
data combine;
set &tables;
run;
=============================
LOG:
45 data combine;
SYMBOLGEN: Macro ... 阅读全帖 |
|
r*********o 发帖数: 490 | 21 我用的code框架如下,sas总是崩溃,有啥好办法?
ods listing close;
ods output ttests=pvals;
proc ttest data=sashelp.class;
class sex;
var col1-col20000;
run;
ods output close;
ods listing; |
|
m*********n 发帖数: 413 | 22 go see SASHELP library. |
|
|
a***d 发帖数: 336 | 24 you can query sashelp.Vcolumn
it contains library name, member name, column Name, column label and so on.
name
件? |
|
y********0 发帖数: 638 | 25 象aloud说的,sashelp.vcolumns里,dictionary.columns都有这些变量信息.
用proc datasets 或者 contents都能输出.
可以把两个文件的名字列表各自输出,然后再merge一下.
这是我能想到的方法,不知道有没有更简单的.
譬如:
proc datasets lib=work nolist;
contents data=one out=vone (keep=name label);
contents data=two out=vtwo (keep=name label);
quit;
data vcombine;
merge vone(in=in_one) vtwo(in=in_two);
by name;
if in_one and in_two then from="AB";
else if in_one and in_two=0 then from="A";
else from="B";
run;
name
件? |
|
o****o 发帖数: 8077 | 26 凑个热闹,给个比较冗长但是通用的解法
data test;
input id $1 v1 3 v2 $5-6 v3 8 v4 $10-11;
cards;
a 1 x2 .
a . 3
a . . x4
b 1 x2 .
b . 3
b . . x4
;
run;
proc sql noprint;
select
case
when(type='char') then cat('length ', compress(name), ' $ ',
length, ';')
else cat('length ', compress(name), ' ', length, ';')
end
into :varlist separated by ' '
from sashelp.vcolumn
where libname='WORK' and memname='TEST'
;
quit;
%put... 阅读全帖 |
|
k*******a 发帖数: 772 | 27 可以用 SAS 的dictionary来找出data有什么variable
data test;
input var1 $ var2 $;
datalines;
3.4 5
4.55 5.3
4 3.444
;
run;
proc sql noprint;
select strip(name)||"_n=input("||strip(name)||",best12.)" into :convert
separated by ";"
from sashelp.vcolumn
where libname="WORK" and upcase(memname)="TEST";
quit;
data test1;
set test;
&convert;
run; |
|
t**s 发帖数: 156 | 28 如果知道有多少variable需要转换,也可以用下面的方法.
假定有100个variable
Data test1;
Set test;
Array allchar(*) _char_;
Array newvar(*) newvar1 - newvar100;
Do i=1 to dim(allchar);
newvar(i)=Input(allchar(i), best.);
End;
Run;
如果不知道, 先找出来
proc sql noprint;
select count(*) into:cnt from sashelp.vcolumn
where libname="WORK" and upcase(memname)="TEST" and upcase(type=)"CHAR";
quit;
Data test1;
Set test;
Array allchar(*) _char_;
Array newvar(*) newvar1 - newvar&cnt;
... 阅读全帖 |
|
p**********o 发帖数: 21 | 29 我只知道用用proc contents,sashelp.vcolumn还不知道呢,学习了
另外,那几个"是什么意思啊?是转义吗? |
|
k*z 发帖数: 4704 | 30 google error message, sas给出了完整的解决方案,9.3M1以后必须修改安装文件才能
用非对应的SID.如果用了就要重新修复SAS注册表,然后去SAS FTP下载 SASHELP的一个
文件 13M去覆盖所有SAS Foundation nls里面的语言,每个语言都要覆盖一次。具体
google.很简单。一步一步来。 |
|
k*z 发帖数: 4704 | 31 google error message, sas给出了完整的解决方案,9.3M1以后必须修改安装文件才能
用非对应的SID.如果用了就要重新修复SAS注册表,然后去SAS FTP下载 SASHELP的一个
文件 13M去覆盖所有SAS Foundation nls里面的语言,每个语言都要覆盖一次。具体
google.很简单。一步一步来。 |
|
j*****7 发帖数: 4348 | 32 libname test "X:\XXX\XXX\XXX";
proc sql noprint;
create table ddfdata as
select memname as dataset label='Data Set Name',
name as variable label='Variable Name',
label label='Variable Label',
type label='Variable Type',
count (distinct memname) into :totmem
from sashelp.vcolumn where libname='TEST'
order by dataset,name;
quit;
%macro trans;
data _null_;
set ddfdata;
by dataset notsorted;
retain b 1;
if first.dataset then do;
call symput(compress(trim(left('member'||t... 阅读全帖 |
|
d******9 发帖数: 404 | 33 Sure.
If you can read them into SAS data, then you can use Dictionary or SASHELP
to retrieve the variable names.
Please note: wild card and data step may not work to read in all the 3000
files , I remember I had a failure before, and later on I figured out why it
failed. It is too complicated to put here.
them? |
|
l******m 发帖数: 111 | 34 楼主是要通过where删选data吗?
那就直接在后面加where好了
proc univariate data=sashelp.class (where=(sex='M')) noprint;
histogram age;
run; |
|
a******p 发帖数: 414 | 35 谢谢你的回答。我也是赶鸭子上架,表述不清楚。
下面的code是我从网上找到的。我的&trt 相当于下面code的里的group,
我的问题是,&trt是macro variable, 我不知怎么向下面一样写format
proc format;
invalue $bmtifmt 'ALL' = 1 'AML-Low Risk' = 2 'AML-High Risk' = 3;
value bmtfmt 1 = 'ALL' 2 = 'AML-Low Risk' 3 = 'AML-High Risk';
run;
data Bmt2;
set sashelp.BMT(rename=(Group=G));
Group = input(input(G, $bmtifmt.), 1.);
label Group = 'Disease Group';
format Group bmtfmt.;
run;
proc LIFETEST data=Bmt2 plots=s(atrisk(outside maxlen=13)=0 to 2500 by 500);... 阅读全帖 |
|
c**d 发帖数: 104 | 36 /* get unique city list from your data */
ods output onewayfreqs = a;
proc freq data = yourdata;
table city;
run;
/* create a look-up table from sas library */
ods output oneayfreqs = b;
proc freq data = sashelp.zipcode;
table city;
run;
/* full join two data sets */
/* you have two ways to do it*/
/* 1: use Perl Regular Expressions functions in sas to match two strings */
/* 2: sas has Functions That Compare Strings (Exact and "Fuzzy" Comparisons)
*/
/* for example: COMPARE COMPLEV CALL COMPCO... 阅读全帖 |
|
l*****e 发帖数: 890 | 37 我的想法是用proc fcmp 定义了CDF 和 PDF是不是就足够了呢?还是需要再定义下
moment estimation?以下是我的code:
proc fcmp library=sashelp.svrtdist outlib=work.sevexmpl.models;
function KumGG_pdf(x,lambda,phi,k, tau, alpha);
dx=x/alpha;
zx=dx**tau;
m=tau*k-1;
igammar=cdf("gamma",zx,k,1);
term1=(lambda*phi*tau)/(alpha*gamma(k));
return (term1*(dx**m)*exp(-zx)*(igammar**(lambda-1))*((1-igammar**
lambda)**(phi-1)));
endsub;
function KumGG_cdf(x,lambda,phi,k, tau, alpha);
dx=x/alpha;
zx=dx**tau;... 阅读全帖 |
|
K***a 发帖数: 72 | 38 Try this:
proc sql noprint;
select count(*), memname into :tb1-:tb100, :numDs
from sashelp.vtable where libname="Urlibname";
quit;
filename outfname ".../Libname.xlsx";
%macro expdt;
%do i = 1 %to &numDs;
proc export data=&&tb&i
outfile=outfname dbms=xlsx replace;
sheet=&&tb&i;
run;
%end;
%mend;
%expdt; |
|
K***a 发帖数: 72 | 39 Correction:
proc sql noprint;
select memname, count(*) into :tb1-:tb100, :numDs
from sashelp.vtable where libname="Urlibname";
quit; |
|
i*********e 发帖数: 783 | 40 * E2_5a.sas
*
求下面一个sas 程序改错,谢谢!
* Chapter 2 Exercise 5
*
* Create a counter for each age group.
* Why does the following fail. Can you fix the problem?;
proc sort data=sashelp.class out=cl1;
by age;
run;
data class;
set cl1;
by age;
if first.age then cnt+1;
run;
title 'Count the Age Groups';
proc report data=class nowd;
column cnt age sex, height;
define cnt / order;
define age / group;
define sex /across;
define height/analysis;
run; |
|
N***3 发帖数: 801 | 41 如果做时间序列可以这样写
%macro loop;
%do i=1 %to 20;
data _null_;
monyy=intnx('month','01dec1999'd,&i);
call symput('yymm',put(monyy,yymmn4.));
run;
proc sql;
create table a_&&yymm as
select put(&&yymm,z4.) as yymm, * from sashelp.cars;
quit;
proc append base=master data=a_&&yymm;
run;
%end;
%mend;
%loop; |
|
Z********6 发帖数: 10 | 42 The answer is D. syslast, the name of the most recently created SAS data set
, seems always uppercased.
%macro cars(dsn=cars,sub=Acura);
data &dsn;
set sashelp.cars;
if make = "&sub";
run;
%mend;
%cars(sub=Audi);
%cars(dsn=ACURA);
%cars(sub=BMW);
%put &syslast.;
*WORK.CARS; |
|
m*********k 发帖数: 10521 | 43 [pets] faithjing Jan 7 ● 大事求祝福--更新,一切顺利
10*95=950
成功奖励 10 伪币的用户: haobuhao, Paladino, nmg, mealone, suanputao, jkwan090, tuguaiguai, spga, duckpear, pl6666, myhoo, havala, Minsco, thyme09, flandy, MiniMac, mariah, yves, gwjess, angelamin, plucklady, YMcDullY, utadamercury, markh, w9918, lcbaby, keeplooking, monokeros, Dulcet, onfire, yadanbenben, AprilLily, bsmile, dede, bjjasmine, Babel, starrynite54, yuki14, paulineli, HifoCH, feitianren, sashelp, Rashel2010, InfernoAngel, pecanpie, lllyy... 阅读全帖 |
|
y*********u 发帖数: 14561 | 44 thanks!
jkwan090, tuguaiguai, spga, duckpear, pl6666, myhoo, havala, Minsco, thyme09
, flandy, MiniMac, mariah, yves, gwjess, angelamin, plucklady, YMcDullY,
utadamercury, markh, w9918, lcbaby, keeplooking, monokeros, Dulcet, onfire,
yadanbenben, AprilLily, bsmile, dede, bjjasmine, Babel, starrynite54, yuki14
, paulineli, HifoCH, feitianren, sashelp, Rashel2010, InfernoAngel, pecanpie
, lllyyyt, carine410, OnSale, janetsu, creatorlh, fbf: b, orzgod, drik,
daxue, samonny, tiantianlele, TigersHea... 阅读全帖 |
|
y*********u 发帖数: 14561 | 45 thanks!
jkwan090, tuguaiguai, spga, duckpear, pl6666, myhoo, havala, Minsco, thyme09
, flandy, MiniMac, mariah, yves, gwjess, angelamin, plucklady, YMcDullY,
utadamercury, markh, w9918, lcbaby, keeplooking, monokeros, Dulcet, onfire,
yadanbenben, AprilLily, bsmile, dede, bjjasmine, Babel, starrynite54, yuki14
, paulineli, HifoCH, feitianren, sashelp, Rashel2010, InfernoAngel, pecanpie
, lllyyyt, carine410, OnSale, janetsu, creatorlh, fbf: b, orzgod, drik,
daxue, samonny, tiantianlele, TigersHea... 阅读全帖 |
|
m*********k 发帖数: 10521 | 46 [Basketball] pandamalone Jan 11 ● s散尽家财发不限量包子祝贺我国四代隐身重型战
10*400*1.1=4400
成功奖励 10 伪币的用户: loveclausius, dannyfulgent, Zeeeero, huamei91106, lovelaker, sckyo, Belichick, wallwallwall, YaoReturn, lg, ManU, iversonkxmd, abrahamfeng, joshuazzx, leftHand, usfish, lxinzheng, paladin, huangshiren, bruclee, luxilon, Drake, TINS, longxi, ZhenZhi, lele1986, bearfire, woshixiao, dreamdate, laomaomao, trigold, TABASCO, larrabee, ldxk, Gg0701, zhenhuay, qidamm, iso35, angelsun, bear, s3, woailanqiu, tan09... 阅读全帖 |
|