csvinputsasraw-datacharacter-limit

Importing data to SAS from a csv file


I'm working with a .csv export of a workout app. It records the date, time, exercise, reps, weight, and comments. Like many .csv files, its a little messy.

Example:

Date,Time,Exercise,# of Reps,Weight,Comments12/23/2014,14:52,Hip Abduction,30,180,12/23/2014,14:52,Hip Abduction,30,180,12/23/2014,14:51,Inverse Bench,15,95,12/23/2014,14:51,Abb Twist,30,100,12/23/2014,14:51,Pull-Ups,5,170,12/23/2014,14:27,Squat,15,135,12/23/2014,14:27,Squat,15,13512/23/2014,14:27,Squat,15,13512/23/2014,14:27,Deadlift,15,135,12/23/2014,14:27,Crunch,30,170,12/23/2014,14:27,Crunch,30,17012/23/2014,14:27,Crunch,30,17012/23/2014,14:26,Bench,15,135,12/23/2014,14:26,Bench,15,13512/23/2014,14:26,Bench,15,135,etc...

I've been able to import the data, however, it is limiting the number of characters to 8; as seen in the date and exercise variables.

SAS Code:

DATA strength;
    infile 'C:\Users\user\Google Drive\strength.csv' DLM = ',' DSD;
    input Date $ Time $ Exercise $ Reps Weight Comments;
    if date = 'Date' then delete;   *removes first obs - the csv header;
RUN;

PROC PRINT data = strength;
    title 'Simple Work Out Log Export';
RUN;

SAS Output:

Obs      Date      Time     Exercise    Reps    Weight    Comments

     1    12/23/20    14:52    Hip Abdu      30      180         .
     2    12/23/20    14:52    Hip Addu      30      180         .
     3    12/23/20    14:51    Inverse       15       95         .
     4    12/23/20    14:51    Abb Twis      30      100         .
     etc...

I don't have a lot of experience working with .csv files, but I did try using

input Date $ Time $ Exercise $ 12. ....

but that didn't work because different exercises have different length names.

How would I go about importing the full date and exercise name for a raw .csv data file like this?

Thanks!


Solution

  • It's also possible to write a slightly more complex input statement that does what you want without using an informat statement:

    input date :mmyydd10. time :time. Exercise :$32. reps :8. weight :8.;
    

    You can then apply date and time formats:

    format date mmddyy10. time time.;