09-28-2012 01:28 PM
I have a dataset where the data is in wide format. I have a range called dx1-dx25 which I'd like to rename diagcde1-diagcde25. I have 3 other ranges like this that will need to be changed.
I searched the site and was able to successfully change singular variable names using "modify" and "rename" but I'm not sure how to do a range. Some of the examples on the sites indicated that I would need to transpose this range first, is that true?
Any and all assistance greatly appreciated.
09-28-2012 01:41 PM
hi ... if you have V9.1 or greater ...
retain dx1-dx3 250;
diagcde1 diagcde2 diagcde3
250 250 250
09-28-2012 01:54 PM
I came up a more complicated one:smileysilly:. you have to change the RED parts to suit your data.
/* create sample dataset */
array _dx dx1-dx25;
do over _dx;
%let lib=work; /* the library of your dataset */
%let dsn=have; /* your dataset name */
proc sql noprint;
select catx('=',name,cats('diagcde',compress(name,,'kd'))) into :names separated by ' '
where libname="%upcase(&lib)" and memname="%upcase(&dsn)" and upcase(substr(name,1,2))='DX';
proc datasets lib=&lib;
proc contents data=&lib..&dsn;run;
09-28-2012 02:06 PM
hi ...PROC DATASETS is the better route (though I'm not sure if it's worth all the extra code with a small data set),
I think it's odd that this type of statement ...
is NOT allowed in PROC DATASETS, only in a data step
ps a paper ... "Renaming in Batches"
09-28-2012 02:14 PM
I asked myself why I always fall with the most strenuous ways of doing things? Of course, proc datasets is the way to go, for just operating on the descriptor. Thanks, Mike.
09-28-2012 03:36 PM
Wow, thanks for the multiple responses in such a short period of time!!
Mike, each dx will have its own code or be blank so do I need to include the 250? Also, how does this work with the singular edits i.e. this is the code thus far without the diagnoses:
rename gender=sex admitcat=admit entrycd=entry dischdate=sepdate totallos=los;
09-28-2012 03:48 PM
Mike's code is not allowed in proc datasets. try adding HaiKuo's code:
%do i=1 %to 25;
proc datasets lib=hims;
rename gender=sex admitcat=admit entrycd=entry dischdate=sepdate totallos=los %renm;
07-08-2015 01:56 PM
Hi I know this post is old but I'm using it now and for some reason the code is excluding the first entry. So I use the renaming code that changes dxcode1 to dx1 but I get the error message "the variable dx1 in the drop, keep or rename list has never been referenced". I know that there is for sure a diagcde1 so why would this be happening? Note that it happens with all the ranges I'm trying to change and not just diagnoses. Any help greatly appreciated.
07-08-2015 02:10 PM
Thanks for the quick response. Below is the code: %macro renm1; %do i=1 %to 20; int_code_&i=pxcde&i; %end; %mend; So pxcde1 to pxcde20 is the current name and I wish to change it to int_code_1 to int_code_20; Thanks.
07-08-2015 02:34 PM
Tom, that caused issues so that now it's indicating that ALL the other ones are uninitialized i.e. variable int_code_2 is uninitialized all the way down to 20. Prior to your response, I changed the do loop to %do i=0 %to 20; int_code_&i=pxcde&i; and that worked for all 20. But I would like to know why I'm getting this error. Thanks.
Need further help from the community? Please ask a new question.