BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
alhs77st
Calcite | Level 5

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!

1 ACCEPTED SOLUTION

Accepted Solutions
Jagadishkatam
Amethyst | Level 16
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

3 REPLIES 3
Jagadishkatam
Amethyst | Level 16
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
alhs77st
Calcite | Level 5

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. 

RW9
Diamond | Level 26 RW9
Diamond | Level 26

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.

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