BookmarkSubscribeRSS Feed
chennupriya
Quartz | Level 8

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

5 REPLIES 5
LinusH
Tourmaline | Level 20

Don't understand what you are saying.

Please provide a complete result data set with X, Y and Z columns.

Data never sleeps
chennupriya
Quartz | Level 8

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

Reeza
Super User

Neither do we, unless you clarify your problem.

In your sample output above where does SC come from and why is PA missing?

chennupriya
Quartz | Level 8

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

Reeza
Super User

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

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!

SAS Enterprise Guide vs. SAS Studio

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.

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
  • 1001 views
  • 0 likes
  • 3 in conversation