08-24-2017 12:46 PM - edited 08-24-2017 01:21 PM
This is my vishal.csv file. How will i read this file in SAS ? I tried to read like below-
infile "vishal.csv" dsd ;
input name$ month$ score1 score2 score3 score4 score5 situatuon$ ;
08-24-2017 12:50 PM
Is there a question here?
Please review the guidelines on how to post a question.
There are video's on the most common tasks here:
08-24-2017 01:41 PM
1. Make sure the path is correct, you usually need the full path
2. You have 4 scores not 5, so trying to read a score5 will mess things up. Remove it from your INPUT list.
08-24-2017 02:07 PM
If you did not copy the lines shown directly from the file then what you show will have issues as some records have 4 scores and others have 5.
If the data is well formed csv the data would look like:
Note the inserted extra comma in lines 1 and 3 where there are only 4 scores to idicate Score5 is missing,
or the extra comma might appear between any score variable and adjacent depending on which score is actually missing.
If you do not have well formed CSV and the actual number of scores varies you will have to do a fair bit of work especially if the number of missing scores is more than 1. It appears that there may be 5 scores only when the situation is "CURRENT" and 4 scores when situation is "FINAL". If that is the case you will have to provide some code to indicate which which line is which.
Something like this:
data abc; infile datalines dlm=',' dsd ; input @; if findw(_infile_,'CURRENT')>0 then input name$ month$ score1 score2 score3 score4 score5 situatuon$ ; else if findw(_infile_,'FINAL')>0 then input name$ month$ score1 score2 score3 score4 situatuon$ ; else input; datalines; JOHN,MAR,11,22,33,44,FINAL JOHN,FEB,55,66,77,88,99,CURRENT TINA,MAR,12,13,14,15,FINAL TINA,FEB,17,18,19,20,21,CURRENT ; run;