- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Please go through the pdf file for full details.
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
@Siddhu welcome to the SAS Community 🙂 Next time you post a question, please do not specify your request in an image file. Describe your problem and provide usable code. Makes it much easier to help you.
Here you go though
data have;
input id type $ A B C;
datalines;
1 A 10 100 200
2 B 15 105 300
3 C 20 120 200
4 B 30 125 300
5 A 25 110 400
;
data want;
set have;
array _{*} A--C;
do i=1 to dim(_);
if vname(_[i])=type then value=_[i];
end;
keep id type value;
run;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
@Siddhu welcome to the SAS Community 🙂 Next time you post a question, please do not specify your request in an image file. Describe your problem and provide usable code. Makes it much easier to help you.
Here you go though
data have;
input id type $ A B C;
datalines;
1 A 10 100 200
2 B 15 105 300
3 C 20 120 200
4 B 30 125 300
5 A 25 110 400
;
data want;
set have;
array _{*} A--C;
do i=1 to dim(_);
if vname(_[i])=type then value=_[i];
end;
keep id type value;
run;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Can you please explain me about the background work of "vname" in SAS arrays. If possible, please try to explain it by a video or post a link as I couldn't get it.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Whenever you encounter a function in SAS you're unsure of, do consult the documentation.
in this case
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Why not use VVALUEX() ?
data want2;
set have;
value=vvaluex(type);
run;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
@Ksharp tbh, didn't even cross my mind 🙂 Kudos!
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Please try the below code
data have;
input id type$ a b c d;
cards;
1 A 1 2 3 4
2 B 1 2 3 4
3 C 1 2 3 4
;
data want;
set have;
array vars(*) a b c d ;
do i = 1 to dim(vars);
if lowcase(type)=lowcase(vname(vars(i))) then value=vars(i);
end;
run;
Jag