BookmarkSubscribeRSS Feed
Ronein
Meteorite | Level 14

Hello

Why is wrong that these 2 data sets are not created well?

 


Data have1;
infile cards;
input CustID date date9.  Ind_Change  balance;
format date date9.;
cards;
111 01JAN2025 0
111 02JAN2025 0
111 03JAN2025 0
111 04JAN2025 1
111 05JAN2025 0
111 06JAN2025 0
111 07JAN2025 0
111 08JAN2025 0
111 09JAN2025 1
111 10JAN2025 0
;
Run;

 
Data have2;
infile datalines dlm="," dsd;
input CustID   date date9.  Ind_Change  balance;
format date date9.;
cards;
111,01JAN2025,0,50
111,02JAN2025,0,80
111,03JAN2025,0,10
111,04JAN2025,1,15
111,05JAN2025,0,30
111,06JAN2025,0,80
111,07JAN2025,0,90
111,08JAN2025,0,140
111,09JAN2025,1,130
111,10JAN2025,0,125
;
Run;
6 REPLIES 6
LinusH
Tourmaline | Level 20

Haven't tried your code, but I think you need an INFORMAT for your date variables.

Data never sleeps
yabwon
Onyx | Level 15

1) add MISSOVER

2) remove DSD

3) read the documentation for INFILE statement:  https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/lestmtsref/n1rill4udj0tfun1fvce3j401plo.htm

 

data have1;
infile cards MISSOVER;
input custid date date9.  ind_change  balance;
format date date9.;
cards;
111 01JAN2025 0
111 02JAN2025 0
111 03JAN2025 0
111 04JAN2025 1
111 05JAN2025 0
111 06JAN2025 0
111 07JAN2025 0
111 08JAN2025 0
111 09JAN2025 1
111 10JAN2025 0
;
Run;

 
data have2;
infile datalines dlm=",";
input custid   date date9.  ind_change  balance;
format date date9.;
cards;
111,01JAN2025,0,50
111,02JAN2025,0,80
111,03JAN2025,0,10
111,04JAN2025,1,15
111,05JAN2025,0,30
111,06JAN2025,0,80
111,07JAN2025,0,90
111,08JAN2025,0,140
111,09JAN2025,1,130
111,10JAN2025,0,125
;
Run;
_______________
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



yabwon
Onyx | Level 15

And if you really have DSD-data then use colon operator(:)

 

Like this:

data have2;
infile datalines dlm="," dsd;
input custid date :date9. ind_change balance XXX :$5.; /* XXX is really DSD-data */
format date date9.;
cards;
111,01JAN2025,0,50,"A,B"
;
Run;
proc print;
run;

B

_______________
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



Tom
Super User Tom
Super User

You almost NEVER want the functionality of the ancient MISSOVER option (to throw away values at the end of the line that are too short).  Instead use the TRUNCOVER option (its only been available for the last 30 years).

 

It is the need to continue to use of LIST MODE input style, which not use only when using DSD option on the infile statement, that requires the colon modifier in front of informat specifications included in the INPUT statement.

yabwon
Onyx | Level 15

TRUNCOVER  - thanks Tom, will use it!

 

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



Kurt_Bremser
Super User

For have1, you try to read four values, but only have three values in each CARDS line. The default FLOWOVER option causes the INPUT statement to read the first value of the following line as the fourth value, and discards the rest, so you miss half of the input lines. Use TRUNCOVER in an INFILE statement to prevent this:

data have1;
infile cards truncover;
input CustID date :date9. Ind_Change balance;
format date date9.;
cards;
111 01JAN2025 0
111 02JAN2025 0
111 03JAN2025 0
111 04JAN2025 1
111 05JAN2025 0
111 06JAN2025 0
111 07JAN2025 0
111 08JAN2025 0
111 09JAN2025 1
111 10JAN2025 0
;

Note the use of the colon modifier to prevent the INPUT statement from switching from list input to formatted input.

 

For have2, once again you must use the colon modifier:

data have2;
infile datalines dlm="," dsd;
input CustID date :date9. Ind_Change balance;
format date date9.;
cards;
111,01JAN2025,0,50
111,02JAN2025,0,80
111,03JAN2025,0,10
111,04JAN2025,1,15
111,05JAN2025,0,30
111,06JAN2025,0,80
111,07JAN2025,0,90
111,08JAN2025,0,140
111,09JAN2025,1,130
111,10JAN2025,0,125
;

Without it, formatted input reads the next 9 characters and disregards any delimiter. For the next (third) variable, the INPUT statement immediately finds a delimiter, which means (because of the DSD option) that a missing value is encountered. The third value is then read into the fourth variable, and the fourth value is discarded.

sas-innovate-wordmark-2025-midnight.png

Register Today!

Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.


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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 6 replies
  • 177 views
  • 3 likes
  • 5 in conversation