Please go through the pdf file for full details.
@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;
@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;
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.
Whenever you encounter a function in SAS you're unsure of, do consult the documentation.
in this case
Why not use VVALUEX() ?
data want2;
set have;
value=vvaluex(type);
run;
@Ksharp tbh, didn't even cross my mind 🙂 Kudos!
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;
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.