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!
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.
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.
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.
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.