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

Hello,

 

Could anyone please explain how SAS processes the following code : 

 

Raw data file (Text file) data :

Ruth  39 11 (39 starts at Col7 and 11 at Col10)

Jose  32 22

Sue   30 33

John 40 44

 

DATA STEP :-

 

data new_1;
infile 'test1.txt';
INPUT EMPLOYEE_NAME $ 1-4;
If employee_name='Ruth' then input idnum 10-11;
else input age 7-8;
run;

 

OUTPUT :-

employee_name=Ruth idnum=22 age=. _ERROR_=0 _N_=1
employee_name=Sue idnum=. age=40 _ERROR_=0 _N_=2
NOTE: The data set WORK.new_1 has 2 observations and 3 variables.

 

I am not able to understand why SAS did not give output for Jose and John.

 

Thank you.

1 ACCEPTED SOLUTION

Accepted Solutions
Shmuel
Garnet | Level 18

Each INPUT statement, when it closed by semicolon (;), reads one line and is ready to read the following one.

 

In order to stay on same line and read more variables from it, you end the read statemnet by:  @;  like next code:

 

data want;

       infile datalines;

       input employee_name $ @;

      if employee_name = 'Ruth'

       then input idnum 10-11;
       else input age 7-8;

datalines;

Ruth  39 11 

Jose  32 22

Sue   30 33

John 40 44

; run;

View solution in original post

2 REPLIES 2
Shmuel
Garnet | Level 18

Each INPUT statement, when it closed by semicolon (;), reads one line and is ready to read the following one.

 

In order to stay on same line and read more variables from it, you end the read statemnet by:  @;  like next code:

 

data want;

       infile datalines;

       input employee_name $ @;

      if employee_name = 'Ruth'

       then input idnum 10-11;
       else input age 7-8;

datalines;

Ruth  39 11 

Jose  32 22

Sue   30 33

John 40 44

; run;

PoojaP1
Fluorite | Level 6
Thank you sir! That was a very nice explanation.

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
  • 2 replies
  • 3090 views
  • 3 likes
  • 2 in conversation