I Have a dataset
x y and I have to create z
x y
CA 02
PA MX
GA FL
BM
HI
i have to create Z variable in dataset and x and y has state codes
when y in 02 then we assign SC some state code but when not numberic then Y as it is but when missing then shd do x=y
and. Now Z.
Z
SC
MX
FL
BM
HI
CAn anyone pls help
Don't understand what you are saying.
Please provide a complete result data set with X, Y and Z columns.
HHi
I have state codes in X and Y but I need to create Z coloumn from Y
and Y has numeric and character data when state codes in 02 they gave me conversion that 02 means SC and 03 means VA but Y has character data also like MX and FL then leave as it is
aand Y has missing data then Z coloumn takes value from X coloumn as Y has missing values we u notice X Y and Z which I gave u above explains it now I am stuck how to create Z
Neither do we, unless you clarify your problem.
In your sample output above where does SC come from and why is PA missing?
hi ,
ok lets go like this
state p_st
XY PA
SC LA
FL
GA
I WANT A CODE WHEN P_ST IS MISSING THEN TAKE A VALUE FROM STATE OTHERWISE P_ST
Use the coalesce function, see the documentation regarding the usage details:
SAS(R) 9.2 Language Reference: Dictionary, Fourth Edition
Z = coalesce(p_st, state);
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!
What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.
Find more tutorials on the SAS Users YouTube channel.