BookmarkSubscribeRSS Feed
Norman21
Lapis Lazuli | Level 10

Hi,

 

I have a file containing responses to a questionnaire, and want to assign the values of some of the variables to new variables, so that I can make use of a macro (more details here: https://medicine.umich.edu/dept/urology/research/epic).

 

Everything works well, except that the new variables don't inherit the labels from the old variables, which is slightly annoying. Is there a way to make this work?

 

Just to spell it out:

attrib SC_EPICB_EPICBQ1 length=$2 label='1. Rectal Urgency';
...
EPICBQ1 = SC_EPICB_EPICBQ1 ;
...
q42 = input(EPICBQ1, 1.);
...

Norman.
SAS 9.4 (TS1M6) X64_10PRO WIN 10.0.17763 Workstation

3 REPLIES 3
Kurt_Bremser
Super User

Use the same attrib statement that you used for the original variable. If you want to do it automatically, get the attributes from sashelp.vcolumn and create the attrib statement(s) into a macro variable.

It all depends on what you finally want to achieve.

 

Automatic assignment of attributes makes no sense, once you think through it.

Astounding
PROC Star

While you can use macro language and dictionary.columns to pick out all the attributes, it's probably easier to make the new variables actually be the old variables.  For example:

 

data new_variables;

set have;

keep id sc_dpicb_epicbq1;

rename sc_dpicb_epicbq1 = epicbq1;

run;

 

data want;

merge have new_variables;

by id;

run;

 

Of course, the first DATA step can keep and rename many more new variables in a single step.

ballardw
Super User

@Norman21 wrote:
Everything works well, except that the new variables don't inherit the labels from the old variables, which is slightly annoying. Is there a way to make this work?
I am not sure why you would expect new variable to inherit from existing as they are new hence different. If you name a new variable of the year value from a date variable would you want it to inherit the format for a date value? A year value of 2016 that inherits a date format is going to be displayed as 1967. Inheriting the label would be very misleading. And if I make a new variable by concatenating four 2-character variables I would likely most often not want a 2 character length or format.
I recode lots of survey variables and often name the recoded from Q1 to RQ1. With the label and formats it is usually easiy enough to copy and paste the original label and formats and then use editor search and replace on a selection of code to change to the new variables.
I hope there is much more going on with your variables because when all you show is creating a new variable and then using INput to change type it raises a question about why not just to the input directly, or even when reading the original data the first time.

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

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
  • 1069 views
  • 4 likes
  • 4 in conversation