I had tried many codes but didn't get solution help me to find out solution
data m;
input v1$ v2$ v3$ v4$;
cards;
v 1 . 2
. 2 b f
. . 4 6
2 . . 9
;
run;
Need output like this
1
b
6
9
Rules.
Computer programs are rules.
I can make your result. But it will not work for anything other than those exact values because you have not provided an rules related to how which value is selected on each row.
If the rule is "second non-missing value" then one way
data want; set m; length value $ 8; value = scan(catx(',',of v:),2,','); run;
which builds a list of values separated by commas with CATX. The Catx function remove trailing blanks so the missing values aren't included when the commas are inserted. The Scan gets the second value.
Note: if your values actually include a comma then use a different character in the first parameter for Catx and the last in Scan.
What is the logic rule for selecting the output value? It's not the first, not the last, not the first letter... I can't see what the rule is.
Rules.
Computer programs are rules.
I can make your result. But it will not work for anything other than those exact values because you have not provided an rules related to how which value is selected on each row.
If the rule is "second non-missing value" then one way
data want; set m; length value $ 8; value = scan(catx(',',of v:),2,','); run;
which builds a list of values separated by commas with CATX. The Catx function remove trailing blanks so the missing values aren't included when the commas are inserted. The Scan gets the second value.
Note: if your values actually include a comma then use a different character in the first parameter for Catx and the last in Scan.
@112211 wrote:
Use coalescec function or mixed of coalescec and other functions
Still not a rule on selecting which values and COALESCE functions select the first that appear in a list of values. So obviously not the the choice for the given example.
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
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.