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
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.
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.
You are not reading the data correctly. Your INFILE and/or INPUT statements need to be modified.
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.