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

SAS Innovate 2025: Call for Content

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!

Submit your idea!

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
  • 1922 views
  • 2 likes
  • 3 in conversation