BookmarkSubscribeRSS Feed
Aman4SAS
Obsidian | Level 7

 Hi All,

 

i have data like below:

 

data test;
input a b c;
datalines;
1 0 0
0 1 0
0 1 1
1 1 1
;
run;

 

i need output with same data added one more variable result as

 

a b c Result

1 0 0 A1

0 1 0 B2

0 1 1 B3

1 1 1 A4

 

please suggest to get the result

 

5 REPLIES 5
Loko
Barite | Level 11

Hello,

 

Could you post the code you tried and / or describe what are the diificulties of building your own solution.

 

Aman4SAS
Obsidian | Level 7

I am not able to imageing anything on it or i can try array and "if " conditions but its not seems good. Can u please suggest if any thing in sort available.

 

Thanks in advance

Reeza
Super User

Your last component appears to be the row and independent of the variable. You can get the row nimbler by using _n_.

 

You say first non missing value but you don't have any missing values in your data set. 

 

Use WHICHN and VNAME to find the variable name

 

Array var_list(3) a b c;

Index = whichn(1, of var_list(*));
First_var = vname(var_list(index));
Aman4SAS
Obsidian | Level 7

0 as missing value and 1 can be anything.. just to simplify i used 0 and 1,

 

 

Reeza
Super User

Making sample data that doesn't reflect your situation means having to answer your question twice. 

 

Youll have to loop through the array then to find your first non missing value. You can use LEAVE to exit a loop. 

 

VNAME can still be used to find variable name and _n_ for row number.  

 

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

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
  • 5 replies
  • 2235 views
  • 2 likes
  • 3 in conversation