BookmarkSubscribeRSS Feed
3 REPLIES 3
yabwon
Onyx | Level 15

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

_______________
Polish SAS Users Group: www.polsug.com and communities.sas.com/polsug

"SAS Packages: the way to share" at SGF2020 Proceedings (the latest version), GitHub Repository, and YouTube Video.
Hands-on-Workshop: "Share your code with SAS Packages"
"My First SAS Package: A How-To" at SGF2021 Proceedings

SAS Ballot Ideas: one: SPF in SAS, two, and three
SAS Documentation



PaigeMiller
Diamond | Level 26

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
;

 

--
Paige Miller
Kurt_Bremser
Super User

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;

SAS Innovate 2025: Call for Content

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!

Submit your idea!

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
  • 552 views
  • 2 likes
  • 4 in conversation