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

Hi, All,

I am a little confused that variable age2 is not showing up.

It will work if      'age2=age*1;'     was put behind     'set have;'   .

Can somebody tell me why?

Thanks.

Joe

data have;

input sex$ age;

datalines;

F 14

M 15

;

data male female;

set have;

if sex='M' then output male;

else if sex='F' then output female;

age2=age*1;

run;

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

Order of operations. Your output statement is before the calculation, so when SAS writes out the observation it hasn't been calculated yet.  

You do get the age2 variable but it is all missing.

View solution in original post

3 REPLIES 3
Reeza
Super User

Order of operations. Your output statement is before the calculation, so when SAS writes out the observation it hasn't been calculated yet.  

You do get the age2 variable but it is all missing.

jiangmi
Calcite | Level 5

Thanks.

Joe

naveen20jan
Obsidian | Level 7

Hi ,

You can use the below set of code ,by moving the age2 before the output statements.

data have;

input sex$ age;

datalines;

F 14

M 15

;

data male female;

set have;

age2=age*1;

if sex='M' then output male;

else if sex='F' then output female;

run;

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