BookmarkSubscribeRSS Feed
Vishal1234
Calcite | Level 5

Hi,

This is my vishal.csv file. How will i read this file in SAS  ? I tried to read like below-

data abc;

infile "vishal.csv" dsd ;

input name$ month$ score1 score2 score3 score4 score5 situatuon$ ;

run;

vishal.csv--

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

3 REPLIES 3
Reeza
Super User

Is there a question here?

 

Please review the guidelines on how to post a question.

https://communities.sas.com/t5/SAS-Communities-Library/How-to-ask-a-question-in-SAS-Analytics-U-Comm...

 

There are video's on the most common tasks here:

support.sas.com/training/tutorial/

Reeza
Super User

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.

ballardw
Super User

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:

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

 

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;

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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
  • 681 views
  • 4 likes
  • 3 in conversation