BookmarkSubscribeRSS Feed
mnew
Calcite | Level 5
Experts:
Any tips on why this does not work? The first value for Name has an embedded blank so between Name and Amount, I used two blanks for the first 3 rows. They read in fine. The last observation does not have a value for Name. I tried to add one or two blanks before the amount (40), but still could not read in the last row correctly.
Thanks!

data work.test;
infile datalines missover DSD DLM=' ';
input Name$ & Amount;
datalines;
Dan Inc 100
Mary 80
John 200
40
;
run;
proc print data=work.test;
run;
10 REPLIES 10
bheinsius
Lapis Lazuli | Level 10
What is the meaning of the & in your code?
sbb
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10
Reading the INPUT statement DOC, it clearly states "...next non-blank column...".

http://support.sas.com/documentation/cdl/en/lrdict/63026/HTML/default/viewer.htm#a000144370.htm

If there is a chance you will have a blank value, then you will need to consider using the _INFILE_ automatic variable to parse your input record with the SCAN function (or possibly using FIND, INDEX/INDEXW/INDEXC).

Scott Barry
SBBWorks, Inc.

Google advanced search argument, this topic / post:

input list format modifier site:sas.com
mnew
Calcite | Level 5
Thank you. Good suggestion. So much to learn.
mnew
Calcite | Level 5
> What is the meaning of the & in your code?

&: see this site
http://support.sas.com/documentation/cdl/en/lrcon/62955/HTML/default/viewer.htm#a003209907.htm

The & (ampersand) format modifier enables you to read character values that contains one or more embedded blanks with list input and to specify a character informat. SAS reads until it encounters two consecutive blanks, the defined length of the variable, or the end of the input line, whichever comes first.
Ksharp
Super User
Hi.
Very interesting.
So used three blanks for the first 3 rows,two blanks for the last row.


[pre]
data work.test;
infile datalines missover dsd DLM=' ';
input Name & $ +1 Amount;
datalines;
Dan Inc 100
Mary 80
John 200
40
;
run;
proc print data=work.test;
run;
[/pre]


Ksharp
mnew
Calcite | Level 5
Thanks! Your code worked. Creative solution :).
Peter_C
Rhodochrosite | Level 12
> read in fine. The last observation does not have a
> value for Name. I tried to add one or two blanks
> before the amount (40), but still could not read in
> the last row correctly.

the thing to add before that 40 is a dot [pre]. 40[/pre] good luck
mnew
Calcite | Level 5
Puzzling but this idea works great too. I originally thought we could not use . as Name is a character variable. Thank you for the reply!
Peter_C
Rhodochrosite | Level 12
the small print in the doc points out that the default informat for char data is $. $CHAR. would return . for ., but $. treats . as "missing" for which the stored value is blank.
mnew
Calcite | Level 5
Thank you. The additional explanation is very helpful.

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
  • 10 replies
  • 1000 views
  • 0 likes
  • 5 in conversation