Use ":" (doc. https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.2/lestmtsref/n0lrz3gb7m9e4rn137op544ddg0v.htm#p...)
data Q2;
input date : mmddyy10. name $ product $ Quantity Amount;
cards;
04262006 Peter Bike 20 1560
;
run;
proc print;
run;
Plus some extras about the ":" https://support.sas.com/resources/papers/proceedings/proceedings/sugi26/p073-26.pdf
Bart
Hello @ChingYee
Although @yabwon has provided a correct answer, let me urge you to read the log when you have problems like this
1 data Q2; 2 input date mmddyy10. name $ product $ Quantity Amount; 3 cards; NOTE: Invalid data for date in line 4 1-10. RULE: ----+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9----+----0 4 04262006 Peter Bike 20 1560 date=. name=eter product=Bike Quantity=20 Amount=1560 _ERROR_=1 _N_=1 NOTE: The data set WORK.Q2 has 1 observations and 5 variables.
Do you see how on this row the value of name is 'eter'? It isn't reading from the right place. It is reading from column 11 to get 'eter', and so columns 1-10 have already been read. That would make the value of date the contents of columns 1-10, or date is '04252006 P' which is not a valid date. This information can be very helpful in figuring out how to fix the problem. You are reading 10 characters for date, when in fact there are only 8 characters. Knowing this, another solution here is to change the informat to MMDDYY8.
data Q2;
input date mmddyy8. name $ product $ Quantity Amount;
cards;
04262006 Peter Bike 20 1560
;
When you use a format like this, the first part of your INPUT statement becomes formatted input, where the width of the format determines exactly how many characters are read.
To make your whole INPUT list input (where the delimiters take precedence over the format widths), you need to use the colon modifier; it is also a good idea to match the format width with the actual length of the data, to avoid confusion when someone (most likely you) reads the code in the future.
input date :mmddyy8. name $ product $ quantity amount;
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.