BookmarkSubscribeRSS Feed
mariapf
Fluorite | Level 6

Hey all,

 

The data that I need to work with is provided to me in a csv that contains all data in a single column of the csv. I can easily separate the data into columns in excel (thus obtaining all of the variables I need), but I need to find a way for SAS to separate the data into columns. 

 

My csv contains in one column all data in this format:

month,year,country,cashflow

06,2018,Germany,23754

12,2011,France,567890

02,2003,Poland,788229

 

And I need to import the data into SAS so that it looks like this (without separating the columns in excel first):

month       year      country      cashflow

06             2018    Germany       23754

12             2011     France        567890

02             2003     Poland        788229

 

Does anyone know how to do this directly in SAS? Thank you in advance

3 REPLIES 3
Kurt_Bremser
Super User

Very simple:

data want;
infile datalines dlm="," dsd truncover;
input month year country :$20. cashflow;
datalines;
06,2018,Germany,23754
12,2011,France,567890
02,2003,Poland,788229
;

Replace the DATALINES option of the INFILE statement with the path to your CSV file.

Tom
Super User Tom
Super User

I am confused by your question. The file you posted looks like a normal CSV (comma separated values) file.  Why do you say it has data in ONE column?  

mariapf
Fluorite | Level 6
you are right! there was some confusion on my part since I am just a beginner in sas programming
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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 2594 views
  • 2 likes
  • 3 in conversation