BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Primohunter
Obsidian | Level 7

Hello everyone,

I am trying to proc print a dataset which contains 8 rows and 9 variables.

it returns ONLY 4 observations for some reason.

thats my first lines of code below...

 

LIBNAME task2 'mypath';
/* OPTIONS VALIDVARNAME=v7; */

 

DATA fstloadtest;
    INFILE 'mypath/test.csv' DLM=',' FIRSTOBS=2 DSD;
    INPUT Date$:10. Home_Team$:40. Away_Team$:40. Home_Score:2. Away_Score:2. Tournament$:40. City$:40. Country$:40. Neutral$:5. Date2;
RUN;

 

The only way it returns all 8 observations, is by deleting one of the input variables. For example i have delete Tournament$:40 and it returns all 8 observations but instead of delete the tournaments observations, it deleted the last variables observations and repositioned the variables.

Any thoughts?

 

Many thanks in advance

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

So your issue is not with reading a dataset, but with reading a text file into a dataset.

 

You should first try the TRUNCOVER option on the INFILE statement so that SAS will not go to a new line when the current line does not have enough fields to satisfy the INPUT statement.

 

Then examine the dataset you get and compare it to the CSV file (should be easy with only 72 values) and make sure there are not some issues in the middle of the lines that is confusing the INPUT statement about where the variables should be read.

 

PS It is strange to the : modifier in the middle of the informat on the INPUT statement.  Place the : modifier before the informat instead. And do not put a space in the middle of the character informat names.

INPUT
  Date : $10. 
  Home_Team : $40. 
  Away_Team : $40. 
  Home_Score : 2. 
  Away_Score : 2. 
  Tournament : $40. 
  City : $40. 
  Country : $40. 
  Neutral : $5. 
  Date2
;

Also is DATE2 really just a number, like 1234?  If it is formatted on the lines of CSV so that a human can understand it as a date then you should probably read it with an appropriate DATE informat and also add a FORMAT statement to attach a format to the variable so it will print in a human readable way.

 

View solution in original post

3 REPLIES 3
Tom
Super User Tom
Super User

So your issue is not with reading a dataset, but with reading a text file into a dataset.

 

You should first try the TRUNCOVER option on the INFILE statement so that SAS will not go to a new line when the current line does not have enough fields to satisfy the INPUT statement.

 

Then examine the dataset you get and compare it to the CSV file (should be easy with only 72 values) and make sure there are not some issues in the middle of the lines that is confusing the INPUT statement about where the variables should be read.

 

PS It is strange to the : modifier in the middle of the informat on the INPUT statement.  Place the : modifier before the informat instead. And do not put a space in the middle of the character informat names.

INPUT
  Date : $10. 
  Home_Team : $40. 
  Away_Team : $40. 
  Home_Score : 2. 
  Away_Score : 2. 
  Tournament : $40. 
  City : $40. 
  Country : $40. 
  Neutral : $5. 
  Date2
;

Also is DATE2 really just a number, like 1234?  If it is formatted on the lines of CSV so that a human can understand it as a date then you should probably read it with an appropriate DATE informat and also add a FORMAT statement to attach a format to the variable so it will print in a human readable way.

 

Primohunter
Obsidian | Level 7
Thanks a lot. that option solved my issue. and thanks for the (:$10) tip!
PaigeMiller
Diamond | Level 26

You are not reading the data correctly. Your INFILE and/or INPUT statements need to be modified.

--
Paige Miller

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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.

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
  • 1043 views
  • 2 likes
  • 3 in conversation