04-27-2013 03:15 PM
Is there a straightforward way in EG to add a prefix (such as year) to a list of 100+ variables? I've found some potential macros I could insert, but I'm wondering if there's another way to do this within EG 5.1.
Thanks in advance for any help you can provide!
04-28-2013 08:37 PM
I have 20 SAS data sets for each of 7 years. One of the problems is that several of the data sets have the same variable names...for example there's an "ËVENT" variable in 5 of the data sets each year. I'm trying to give the variables in the 20 data sets a prefix that identifies the year and data set. Since I'm working with SAS datasets I haven't been importing anything, just opening them...maybe I'm missing something?
04-29-2013 02:35 PM
I may not be following your suggestion, but the other issue is that several of the data sets within the same year contain the same variable names. Currently it looks like this:
ID Name Event1 Event2
ID Event1 Var5 Var7
ID DQ Event1 Event2
So what I'm trying to do is add a prefix to the variable "Event" so I'll know the year and data set, to get something like " _05_OP_Event1", "_05_IP_Event1" and "_05_RX_Event1". 2006 would be "_06_OP_Event1", etc. At least that's what I think I'm trying to do...
04-29-2013 02:46 PM
You should add variables to your dataset instead. This way you can filter more easily in your queries later on, rather than try and sort through a ton of variables.
There are reasons why you may not want the type split out like this, if you're trying to create a patient level records for instance, but year should probably go like this. It really depends on what you plan to do with it downstream. The benefit of this method is you can proc transpose it later on and use some of the auto renaming options available.
ID Name EVENT1 EVENT2 Type Year
04-29-2013 02:57 PM
In essence I am trying to create patient level records and associated survey responses. I'll be doing cross-sectional and longitudinal analysis...so it sounds like you're suggesting I think about the data set up in terms of person-year rather than just person for cross-sectional analysis? Get at the 2005 records/responses by selecting by year=2005, etc. And when I get to the longitudinal analysis use the proc transpose to give me the wide file?
04-28-2013 10:24 PM
Well, if they are SAS tables, then try following code, it will put table names as prefix for all variables in the corresponding table.
/*get the names of all of your tables*/
proc sql NOPRINT;
select DISTINCT cats( MEMNAME) into SN SEPARATED BY ' ' from dictionary.columns where LIBNAME='YOURLIBNAME';QUIT;
%DO I=1 %TO %SYSFUNC(COUNTW(&DSN));
proc sql NOPRINT;
select cats(name,'=',memname,'_',name) into :ren SEPARATED BY ' ' from dictionary.columns where LIBNAME='YOULIBNAME' AND MEMNAME="&DS";QUIT;
PROC DATASETS LIB=WORK;