BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
tianerhu
Pyrite | Level 9
data work.test;
   
   infile datalines;
   input 
      Name $ 1-14/
	  Address $ 1-14/
	  City $ 1-12;
	if City = 'New York ' then input @1 State $2.;
	else input;
datalines;
Joe Conley
123 Main St.
Janesville
WI
Jane Ngyuen
555 Alpha Ave.
New York
NY
Jennifer Jason
666 Mt.Diablo
Eureka
CA
;
run;
proc print data = work.test;
run;

 

What is the 'else input' mean?


if the city = New York then input NY ,  in' else input' , input what ? 

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

I commented the code for you. 

 

*read from data below this step;  
 infile datalines;

*reads in the first three lines with Name, City and Address;
   input 
      Name $ 1-14/
	  Address $ 1-14/
	  City $ 1-12;

      *check if City is New York and if true, read the next line into the STATE variable;
	if City = 'New York ' then input @1 State $2.;
       *reads in the next line (STATE) but does nothing with it. It is stored in the automatic variable _infile_ but is not used anywhere unless explicitly referenced;
	else input;

The documentation is also helpful:

 

INPUT <specification(s)> <@ | @@>;

Without Arguments

The INPUT statement with no arguments is called a null INPUT statement. The null INPUT statement
  • brings an input data record into the input buffer without creating any SAS variables
  • releases an input data record that is held by a trailing @ or a double trailing @.
     

    @tianerhu wrote:
    data work.test;
       
       infile datalines;
       input 
          Name $ 1-14/
    	  Address $ 1-14/
    	  City $ 1-12;
    	if City = 'New York ' then input @1 State $2.;
    	else input;
    datalines;
    Joe Conley
    123 Main St.
    Janesville
    WI
    Jane Ngyuen
    555 Alpha Ave.
    New York
    NY
    Jennifer Jason
    666 Mt.Diablo
    Eureka
    CA
    ;
    run;
    proc print data = work.test;
    run;
    

     

    What is the 'else input' mean?


    if the city = New York then input NY ,  in' else input' , input what ? 


View solution in original post

4 REPLIES 4
Reeza
Super User

I commented the code for you. 

 

*read from data below this step;  
 infile datalines;

*reads in the first three lines with Name, City and Address;
   input 
      Name $ 1-14/
	  Address $ 1-14/
	  City $ 1-12;

      *check if City is New York and if true, read the next line into the STATE variable;
	if City = 'New York ' then input @1 State $2.;
       *reads in the next line (STATE) but does nothing with it. It is stored in the automatic variable _infile_ but is not used anywhere unless explicitly referenced;
	else input;

The documentation is also helpful:

 

INPUT <specification(s)> <@ | @@>;

Without Arguments

The INPUT statement with no arguments is called a null INPUT statement. The null INPUT statement
  • brings an input data record into the input buffer without creating any SAS variables
  • releases an input data record that is held by a trailing @ or a double trailing @.
     

    @tianerhu wrote:
    data work.test;
       
       infile datalines;
       input 
          Name $ 1-14/
    	  Address $ 1-14/
    	  City $ 1-12;
    	if City = 'New York ' then input @1 State $2.;
    	else input;
    datalines;
    Joe Conley
    123 Main St.
    Janesville
    WI
    Jane Ngyuen
    555 Alpha Ave.
    New York
    NY
    Jennifer Jason
    666 Mt.Diablo
    Eureka
    CA
    ;
    run;
    proc print data = work.test;
    run;
    

     

    What is the 'else input' mean?


    if the city = New York then input NY ,  in' else input' , input what ? 


jimbarbour
Meteorite | Level 14

Everything Reeza said, and I added the following statement after the INPUT statements:

    	PUTLOG	"NOTE:  "  _INFILE_  State=;

Which yields:

NOTE:  WI                                                                              State= 
NOTE:  NY                                                                              State=NY
NOTE:  CA                                                                              State= 

Do you see how Wisconsin and California are present when the PUTLOG executes with _INFILE_ but are blank when PUTLOG executes with State -- but New York is present.  

 

The Null Input reads the record and moves the pointer to the next record but does NOT populate any SAS variables (i.e. "State").

 

Jim

 

 

tianerhu
Pyrite | Level 9

Thanks a lot.

tianerhu
Pyrite | Level 9

Thank you for your help.

SAS Innovate 2025: Call for Content

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 16. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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