DATA Step, Macro, Functions and more

Reading data in Datalines

Accepted Solution Solved
Reply
New Contributor
Posts: 2
Accepted Solution

Reading data in Datalines

When I run the following command in SAS Studio:

 

data test;
    input @1 Subj $3.;
    datalines;
    001
    ;
run;

 

It returns 00 for the lone entry in Subj; however, if I change $3. to $4., Subj now contains 001. I'm new to SAS programming, so this is probably something obvious, but I'd appreciate any help I can get in understanding what's going on here.

 

Thanks!


Accepted Solutions
Solution
‎12-22-2016 02:44 AM
Trusted Advisor
Posts: 1,137

Re: Reading data in Datalines

it is certainly due to blank spaces present before the value 001. SAS will also consider blank spaces as blank data. Please remove the space before 001 and then execute. It will read the data as 001 even if you mention $3.
Thanks,
Jag

View solution in original post


All Replies
Solution
‎12-22-2016 02:44 AM
Trusted Advisor
Posts: 1,137

Re: Reading data in Datalines

it is certainly due to blank spaces present before the value 001. SAS will also consider blank spaces as blank data. Please remove the space before 001 and then execute. It will read the data as 001 even if you mention $3.
Thanks,
Jag
New Contributor
Posts: 2

Re: Reading data in Datalines

Posted in reply to Jagadishkatam

Thanks -- that was definitely it. SAS was reading the tab at the beginning of the line (automatically inserted by the editor) as a blank character. 

Super User
Super User
Posts: 7,942

Re: Reading data in Datalines

Yes, datalines are always left aligned, so the pointer starts reading your data from column 1:

data test;
    input @1 Subj $3.;
    datalines;
    001

^
    ;
run;

 

Read pointer indicated by ^.  Two tips, align the semicolon at column1 also.  Instead of using tabs - which can cause confusion and render differently on different editors, use spaces.  You can use the option in SAS (assuming you have base - not sure where the option is in Enterprise Guide for instance), with an Enhanced Editor window selected choose Tools->Options->Enhanced Editor.  And then in the dialog that appears look down to the Tabs section, there is a checkbox for Insert Spaces for Tabs.  Check this and when you press tab from then on it will insert the number of spaces defined in Tab Size.  Spaces should always render the same across text editors and so your code always appears the same.

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 3 replies
  • 207 views
  • 0 likes
  • 3 in conversation