DATA Step, Macro, Functions and more

& and missing value

Reply
Frequent Contributor
Posts: 100

& and missing value

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;
Regular Contributor
Posts: 182

Re: & and missing value

What is the meaning of the & in your code?
Super Contributor
Super Contributor
Posts: 3,174

Re: & and missing value

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
Frequent Contributor
Posts: 100

Re: & and missing value

Thank you. Good suggestion. So much to learn.
Frequent Contributor
Posts: 100

Re: & and missing value

> 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.
Super User
Posts: 9,681

Re: & and missing value

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
Frequent Contributor
Posts: 100

Re: & and missing value

Thanks! Your code worked. Creative solution Smiley Happy.
Valued Guide
Posts: 2,175

Re: & and missing value

> 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
Frequent Contributor
Posts: 100

Re: & and missing value

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!
Valued Guide
Posts: 2,175

Re: & and missing value

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.
Frequent Contributor
Posts: 100

Re: & and missing value

Thank you. The additional explanation is very helpful.
Ask a Question
Discussion stats
  • 10 replies
  • 227 views
  • 0 likes
  • 5 in conversation