- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
I have a dataset of this format.
A B C D Name
Apple Bat Cat 100 A
Grapes Ball Dog 200 C
Orange Racket Cow 300 D
Now I want another column name Concatenate where first concatenation variable is the column name (NAME) and the second column
depends on the value of the column (NAME) i.e.
Concatenate
AApple
CDog
D300
Is this possible in SAS..??
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
I really like the function VVALUEX(var) which returns the value of the variable specified in the variable var, ex. in your case:
new = cats(name,vvaluex(name));
//Fredrik
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
data; set;
if name='A' then concat=catt(name,a);
if name='B' then concat=catt(name,b);
if name='C' then concat=catt(name,c);
if name='D' then concat=catt(name,d);
Jim
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Actually the thing is columns are not fixed and I want to find the column to be concatenated depending on the value taken by column NAME.
A B C D Name
Apple Bat Cat 100 A
Grapes Ball Dog 200 C
Orange Racket Cow 300 D
Concatenate
AApple
CDog
D300
So when the value is A then take the value of column A and if it changes to D then it automatically takes the value of D and concatenate the column NAME with column D.
The main problem is columns are not fixed.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
data; input a$ b$ c$ d name $;
cards;
Apple Bat Cat 100 A
Grapes Ball Dog 200 C
Orange Racket Cow 300 D
proc print; run;
data; set;
if name='A' then concat=catt(name,a);
if name='B' then concat=catt(name,b);
if name='C' then concat=catt(name,c);
if name='D' then concat=catt(name,d);
proc print; run;
This works for me. columns are not fixed. Jim
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
data have; input (A B C D Name) ($); want=cats(name,vvaluex(name)); cards; Apple Bat Cat 100 A Grapes Ball Dog 200 C Orange Racket Cow 300 D ; run;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
It's easier if you can assume that you want to work with all character variables except NAME. If that's not the case, you will need a way to come up with all the proper variable names:
data want;
if 5=4 then do;
set have (drop=name);
array chars {*} _character_;
end;
set have;
length concatenate $ 40;
do _n_=1 to dim(chars) until (concatenate > ' ');
if name = vname(chars{_n_}) then
concatenate = catt(name, chars{_n_});
end;
run;
It's untested, so might need a small amount of debugging.
That being said, I like what KSharp did (but wonder what would happen if NAME is incorrect and doesn't actually match anything).
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
I really like the function VVALUEX(var) which returns the value of the variable specified in the variable var, ex. in your case:
new = cats(name,vvaluex(name));
//Fredrik
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Tkank You So Much. 🙂
It worked prefectly.