- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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 ;
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
So did you actually try my suggestion, or did you just decide that it wouldn't work?
if 5=4 then agenew = age;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
@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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
@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;