LISTSERV at the University of Georgia
Menubar Imagemap
Home Browse Manage Request Manuals Register
Previous messageNext messagePrevious in topicNext in topicPrevious by same authorNext by same authorPrevious page (April 2008, week 2)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Fri, 11 Apr 2008 10:57:26 -0700
Reply-To:     shiling99@YAHOO.COM
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:         Shiling Zhang <shiling99@YAHOO.COM>
Organization: http://groups.google.com
Subject:      Re: Reading a lists of vars into a macro var
Comments: To: sas-l@uga.edu
Content-Type: text/plain; charset=ISO-8859-1

On Apr 9, 5:54 pm, crisgu...@YAHOO.COM ("P. Cristian Gugiu") wrote: > Is there a way to read a list of vars and save each variable in a macro > variable? > > Say I have a macro varliable &VarList in which I vars below. Is there a > way to create a macro var that reads the vars contained between ALT and > Creatinine__Ur, such that it lists all the vars in a new macro var? Proc > univariate below is giving me trouble. It will not accept a list of vars > such as ALT--Creatinine__Ur because probn wants the vars listed out, such > as ALT Glucose Potassium Sodium Triglycerides Creatinine__Ur. My list is > considerably long so I don't want to type it out. I thought about > assigning the first list to an array in a data step and then using the do > over to build a new macro var but I have not been very successful so far. > Can someone help. Thanks, Cristian > > %Let VarList = ALT--Creatinine__Ur ; > proc univariate data=&Myfile gout=Out.&QQplots ; > var &VarList; > histogram / normal(midpercents) endpoints=&min to &max ; > output out=prob probn=&VarList; > run;

There is a much simpler solutions than you thought. It depends how much you know your data. Basicly you can levelage the functions of retain, keep, view.

HTH

1) if the order of macro varlist ( ALT--Creatinine__Ur) is the same as that in data, then a keep data t1; retain a b u ALT c dr de Creatinine__Ur st e; array x(*) a b u ALT c dr de Creatinine__Ur st e; do i = 1 to 100; do j = 1 to dim(x); x(j)=rannor(123); end; output; end; run;

proc univariate data=t1(keep=ALT--Creatinine__Ur) gout=out ; var _all_; histogram / normal(midpercents) endpoints=-2 to 2 ; run;

2) if it is different, then you may build a data set view + retain to have a desired variable order.

%let varlist=a ALT b c Creatinine__Ur de dr e st u;

data varn/view=varn; retain &varlist; set t1; keep ALT--Creatinine__Ur ; run;

proc univariate data=varn gout=out ; var _all_; histogram / normal(midpercents) endpoints=-2 to 2 ; run;

%let varlist=a ALT b c Creatinine__Ur de dr e st u;

3) similar as 2) but it passes the needed variable to macro variable varlist_n. data varlist; retain &varlist; stop; set t1; keep ALT--Creatinine__Ur ; run;

proc sql noprint; select name into :varlist_n separated by ' ' from dictionary.columns where libname eq 'WORK' and memname eq 'VARLIST' ; quit;

%put &varlist_n;

proc univariate data=t1(keep=&varlist_n) gout=out ; var _all_; histogram / normal(midpercents) endpoints=-2 to 2 ; run;


Back to: Top of message | Previous page | Main SAS-L page