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 ?
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:
@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 ?
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:
@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 ?
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
Thanks a lot.
Thank you for your help.
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!
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.