Hi,
In my data set I have columns
C1 C2 C3 ------C20 C30----C41;
There are no columns with names from C21--- C29
I require to assign label to those columns
From c1 to c20
ATTRIB C1 LABEL='APP C1'
ATTRIB C2 LABEL='APP C2';
From C30 to C41
ATTRIB C30 LABEL ='DEN C30';
ATTRIB C31 LABEL='DEN C31';
I tried to use array to do that but it is not working.
Any help will be appreciated.
There is no fast/easy way to do this, besides a macro or code gen.
If its a one time operation, I'll usually do it in Excel instead to get the statements I need.
You can create labels from data with PROC TRANSPOSE. This example assumes that all C: variables are the same type and numeric. If your situation is more complicated we can fix that, but you will need to describe what you actually have.
My suggested approach is similar to data_null_'s, but I like to use a data _null_ step as a code generator. e..g.:
/*create a data set for testing purposes*/
data have;
retain c1-c20 (20*1);
retain c30-c41 (12*1);
output;
run;
/*create an include file*/
filename dolabels temp;
data _null_;
set have (obs=1);
file dolabels;
array APPDEN{*} c1-c20 c30-c41;
length varname $32;
put "label";
do i=1 to dim(APPDEN);
varname=vname(APPDEN(i));
put varname @;
if i lt 21 then put '="APP '@;
else put '="DEN '@;
put varname @;
put '" ';
end;
put ';';
run;
/*Run the include file in a data step */
data want;
array APPDEN{*} c1-c20 c30-c41;
set have;
%inc dolabels;
run;
For N this small it is easy to just type one label statement and replicate and make the changes by hand.
Now if I still had access to WYLBUR editor (http://dl.acm.org/citation.cfm?id=362234) the CHANGE command to do the modifications for you in a one line command, but I haven't used MVS in 25 years and I doubt anyone who is still uses WYLBUR.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.
Find more tutorials on the SAS Users YouTube channel.