BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Sunny_Sun
Calcite | Level 5

Hi,

I am transforming some variables and want to keep their labels.

For example,

I took 3 months lags on each variable of interest.

proc expand data=in_a out=out_b method = none;

     id time;

     %inn_cvt(innvar3=&&inxvar&inn_i3.., innlg=3);

run;

where &&inxvar&inn_i3.. loop through a bunch of variables. After this transformation, I want to keep the label of pre-transform variable, but edit label for after-transform variable as " pre-transform variable label + Lag 3"

How can I do it? 

Thanks in advance.

Thanks,

Sunny

1 ACCEPTED SOLUTION

Accepted Solutions
evp000
Quartz | Level 8

Hi,

Something like this might do the trick:

data test1;

    attrib var1 label = 'Label of var 1'

           var2 label = 'Label of var 2'

           var3 label = 'Label of var 3';

    var1 = 1;

    var2 = 2;

    var3 = 3;

run;

proc contents data = test1 out = contents_test1 (keep = name label) ; run;

data contents_test2;

    set contents_test1;

    length labelname $100;

    labelname = 'label_'||strip(name);

run;

data _null_;

    set contents_test2;

    call symputx(labelname, label);

run;

%macro do_stuff(innlg= );

%do i = 1 %to 1;

    %put;

    %put i = &i;

    %put varname for &i -> &&varname&i;

    /* get label using varname */

    %put label for &&varname&i -> &&&&label_&&varname&i;

    %let new_label = Pre-transform &&&&label_&&varname&i + &innlg;

    %put new label = &new_label;

%end;

  

%mend;

%do_stuff(innlg = 3);

View solution in original post

3 REPLIES 3
ballardw
Super User

You might want to use the VLabel function prior to the current step you are working with to add the labels of the desired variables.

Another approach would be to collect the information about the variables in your input data set before the step and then use the information after the expand to modify the labels.

proc sql;

     create table variableinformation as

     select *

     from dictionary.columns

     where member='IN_A' and libname='WORK';

quit;

Use the data in the resulting data set variableinformation to create the new labels and assign via proc datasets would be on way.

evp000
Quartz | Level 8

Hi,

Something like this might do the trick:

data test1;

    attrib var1 label = 'Label of var 1'

           var2 label = 'Label of var 2'

           var3 label = 'Label of var 3';

    var1 = 1;

    var2 = 2;

    var3 = 3;

run;

proc contents data = test1 out = contents_test1 (keep = name label) ; run;

data contents_test2;

    set contents_test1;

    length labelname $100;

    labelname = 'label_'||strip(name);

run;

data _null_;

    set contents_test2;

    call symputx(labelname, label);

run;

%macro do_stuff(innlg= );

%do i = 1 %to 1;

    %put;

    %put i = &i;

    %put varname for &i -> &&varname&i;

    /* get label using varname */

    %put label for &&varname&i -> &&&&label_&&varname&i;

    %let new_label = Pre-transform &&&&label_&&varname&i + &innlg;

    %put new label = &new_label;

%end;

  

%mend;

%do_stuff(innlg = 3);

data_null__
Jade | Level 19

It is possible to write some macro code using SAS data set access function or depending on the version of SAS you are using DOSUBL. 

The details of your macro %INC_CVT will also play a role in how it can be implemented.

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

What is Bayesian Analysis?

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 3 replies
  • 3219 views
  • 6 likes
  • 4 in conversation