03-09-2012 04:49 PM
I have a dataset with about 500 variables. The all startwith the prefix “ftc”. So, ftc1, ftc2, ftc3, ftc4…. I have to assign a label to each one removing the “ftc” and replacing it with a “Q” so Q1, Q2, Q3, Q4. Isthere a ay to do this to a very large group of variables at once?
03-09-2012 04:54 PM
/*create test file*/
retain ftc1-ftc500 (500*1);
set have (rename=(ftc1-ftc500=q1-q500));
Now that I have also seen my colleague's responses, I have to wonder if I correctly interpreted what you wanted. My approach was simply renaming the variables. Is that what you wanted to or, as in your subject line, did you actually want to assign labels?
If it is the latter, please disregard my response.
03-09-2012 05:01 PM
- If you have a good editor you could just do it in the editor. If I still had WYLBUR I could do it with a couple of change commands.
- Macro logic.
- Data step logic to write to a file.
- Proc sql to store code in a macro variable.
Once youve generated the variable labels pairs then you also have options on how to apply them.
- DATA step to create a new (or overwrite the old) dataset by reading the existing one.
- PROC SQL code to do the same.
- PROC DATASETS MODIFY code to just modify the labels of the variables without having to create (re-create) the dataset.
filename code temp;
put 'label ';
do i=1 to 500;
put 'ftc' i '="Q' i '"' ;
03-09-2012 05:44 PM
hi ... another idea
retain ftc1-ftc100 1 a b c 'other';
proc sql noprint;
select catt(name, '= "Q' , compress(name,,'kd'),'"') into :labels separated by ' '
from dictionary.columns where libname eq 'WORK' and memname eq 'X' and name eqt 'ftc';
proc datasets lib=work nolist;