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.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.