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

 

I would like to apply same attributes what ever we have for “age” variable to “agenew” variable.

 

Note: I don't want to create any macro/macro variable for this. 

          I need to do this in same data set. 

   

 

For example:

 

data test;

       set sashelp.class;

      agenew = put(age,best.);

run ;

 

 

1 ACCEPTED SOLUTION
7 REPLIES 7
Astounding
PROC Star

If you want the same values, just use:

 

agenew = age;

 

If you just want the attributes and not the values, use:

 

if 5=4 then agenew = age;

 

This requires that AGENEW is not yet part of the incoming data.

bhanuprakash
Obsidian | Level 7

Thanks for the reply.

 

Sorry to say that but my question is completely different.

 

I want to apply the same attributes(length, type, informat and format etc ) what ever we have for “age” variable to “agenew” variable.

Astounding
PROC Star

So did you actually try my suggestion, or did you just decide that it wouldn't work?

 

if 5=4 then agenew = age;

Kurt_Bremser
Super User

How about this:

data want;
merge
  sashelp.class
  sashelp.class (keep=age rename=(age=agenew))
;
agenew = .; /* add any processing you want to do, but make sure you get results of the correct type */
run;
andreas_lds
Jade | Level 19

@bhanuprakash wrote:

 

I would like to apply same attributes what ever we have for “age” variable to “agenew” variable.

 

Note: I don't want to create any macro/macro variable for this. 

          I need to do this in same data set. 

   

 

For example:

 

data test;

       set sashelp.class;

      agenew = put(age,best.);

run ;

 

 


There are no commands to clone the attributes of a variable, except using the merge suggested by @Kurt_Bremser. The functions open, attrn and attrc can read the attributes of a variable, but there are no functions to change those attributes in a datastep.

data_null__
Jade | Level 19

  


@bhanuprakash wrote:

 

I would like to apply same attributes what ever we have for “age” variable to “agenew” variable.

 

Note: I don't want to create any macro/macro variable for this. 

          I need to do this in same data set. 

   

 

For example:

 

data test;

       set sashelp.class;

      agenew = put(age,best.);

run ;

 

 


You can convert numeric to character using PROC TRANSPOSE.  For example.

 

proc transpose data=sashelp.class(obs=3)  out=flip;
   by name;
   var sex--weight;
   copy sex--weight; 
   attrib _all_ label='Example Label';
   format _numeric_ 8.2;
   run;
proc print data=flip(obs=10);
   run;
proc transpose data=flip out=flop(drop=_:) prefix=New_;
   by name;
   copy sex--weight;
   id _name_;
   idlabel _label_;
   var col1;
   run;
proc print;
   run;

 

Capture.PNGCapture2.PNG 

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 7 replies
  • 3806 views
  • 1 like
  • 5 in conversation