BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Siddhu
Fluorite | Level 6

Please go through the pdf file for full details. 

1 ACCEPTED SOLUTION

Accepted Solutions
PeterClemmensen
Tourmaline | Level 20

@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;

View solution in original post

6 REPLIES 6
PeterClemmensen
Tourmaline | Level 20

@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
Fluorite | Level 6

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.

PeterClemmensen
Tourmaline | Level 20

Whenever you encounter a function in SAS you're unsure of, do consult the documentation.

 

in this case

 

SAS Documentation: VNAME Function

Ksharp
Super User

Why not use VVALUEX()  ?

 

data want2;
 set have;
 value=vvaluex(type);
run;
PeterClemmensen
Tourmaline | Level 20

@Ksharp tbh, didn't even cross my mind 🙂 Kudos!

Jagadishkatam
Amethyst | Level 16

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;
Thanks,
Jag

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 6 replies
  • 1410 views
  • 2 likes
  • 4 in conversation