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

Please help -

 

I am trying to have an end result of one number from 4 columns.  If column 1 is not blank, then show column 1, if it is blank, show column 2, if column 2 blank show column 3, if column 3 blank use column 4 and if column 4 is blank, leave blank.  I used the following expression but I am clearly doing something wrong.  Any help would be appreciated.

 

ifn(t1.'Material Group'n not missing,t1.'Material Group'n, ifn(t1.'Material Group #'n not missing, t1.'Material Group #'n), ifn(t1.'Matl Grp'n not missing, t1.'Matl Grp'n, ifn(t1.'Material Group #1'n not missing, t1.'Material Group #1'n, "")))

1 ACCEPTED SOLUTION
2 REPLIES 2
Krueger
Pyrite | Level 9

If you provide some example data and the log it would be helpful in troubleshooting what your issue is. 

 

Below I've provided an example of what I assume you are trying to do. You can try to make necessary corrections on your side from there.

 

data have;
	input a b c d;
	datalines;
	1 . . .
	. 3 . .
	. . 4 .
	. . . 2
	;
run;

data want;
	set have;
	test = ifn(not missing(a), a, ifn(not missing(b), b, ifn(not missing(c), c, ifn(not missing(d), d,0))));
run;

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 1042 views
  • 1 like
  • 3 in conversation