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 ;
Not possible in any way. age is numeric, agenew will be character by definition, so there's no way they could have the same attributes.
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.
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.
So did you actually try my suggestion, or did you just decide that it wouldn't work?
if 5=4 then agenew = age;
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;
Not possible in any way. age is numeric, agenew will be character by definition, so there's no way they could have the same attributes.
@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.
@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;
Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!
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.
Ready to level-up your skills? Choose your own adventure.