BookmarkSubscribeRSS Feed
always-good
Obsidian | Level 7

Hello, everyone!

I have variables in my CSV data, in date format like the calving date of 17/06/2020.

I do know how SAS can read all the CSV data.

I used this code to enter my data

filename BSMB'C:\Users\Ebtissem\Desktop\BSMB\ebtissem.csv';
data farm;
infile BSMB firstobs=2 dlm=';';
input Period THIPeriod Month THIIMonth ID breed Parity DIMMilk TOTALMilk FAT FM PROTEIN PM SC SCS Dryingperiod Gestationperiod Nins LastI Calvingdate previouscalving  CCinterval ICIf IIIplus trpi Icoit Concprate diestrus metestrus estrus proestrus  RT HR RR PS;
run;

PS: I write in red color the variables containing date format.

and here is the first two rows'screenshot of some observations in CSV data.

How can I input the variables in the write format  and not obtain invalid data.

Thank you!

alwaysgood_0-1674304019777.png

 

 

 

1 REPLY 1
Tom
Super User Tom
Super User

 

If you want the data step to read strings like '17/06/2020' from the text file then tell that by assigning the DDMMYY informat to the variable.  If you want the date values that generates to print in a way that humans can understand then attach a date type format.  It would recommend not using the DDMMYY or the MMDDYY format because either one will confuse 50% of your audience.  Use DATE or YYMMDD and you will not risk having users confuse January sixth for the first of June. Also you will want to use the DSD option when reading a delimited file. Otherwise empty values might cause SAS to misalign the columns.  And add the TRUNCOVER option in case any of the lines have fewer values that expected.

 

data farm;
  infile BSMB firstobs=2 dsd dlm=';' truncover;
  input Period THIPeriod Month THIIMonth ID breed Parity DIMMilk TOTALMilk 
        FAT FM PROTEIN PM SC SCS Dryingperiod Gestationperiod Nins LastI 
        Calvingdate previouscalving  CCinterval ICIf IIIplus trpi Icoit Concprate
        diestrus metestrus estrus proestrus  RT HR RR PS
  ;
  informat LastI Calvingdate previouscalving diestrus metestrus estrus proestrus ddmmyy.;
  format LastI Calvingdate previouscalving diestrus metestrus estrus proestrus yymmdd10.;
run;

 

NOTE: You did not show what your CSV file looks like.  So the actual date strings might be in a style that the DDMMYY informat cannot read.  That is because you posted a screenshot of some type of SPREADSHEET.  A CSV file is a text file.  That is critical because a spreadsheet program, like EXCEL, might have changed how the date values are displayed after it read in the CSV file. To share sample lines of of the text file just open it with any text editor (SAS editor will work) and copy and paste a few of the lines of text into the window you get when you press the Insert Code icon (looks like < / > ) on this forum's edit screen.

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 1 reply
  • 475 views
  • 1 like
  • 2 in conversation