DATA Step, Macro, Functions and more

How to get all the columns from CSV file

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 5
Accepted Solution

How to get all the columns from CSV file

Dear All,

 

I am infant to SAS and this is my first post on SAS , 

Uploaded CSV file to one of my folder and also able to read the data from csv file .,But I would like to get all the columns of CSV file .Can any one help me how can I do it

 

data tableau;
 infile '/folders/myfolders/DataFiles/SuperstoreSales.csv' delimiter=',' firstobs=2 ;
  input RowID OrderID Order Date$ Profit$;
 run;
 
 proc print data=tableau;
 run;

 


Accepted Solutions
Solution
‎05-10-2017 03:57 AM
SAS Super FREQ
Posts: 708

Re: How to get all the columns from CSV file

Posted in reply to siddiqalimd

Hi

 

Why not use Proc IMPORT, like so

 

proc import
  file="/folders/myfolders/DataFiles/SuperstoreSales.csv"
  out=tableau
  dbms=csv
  replace
;
run;

Bruno

View solution in original post


All Replies
Trusted Advisor
Posts: 1,568

Re: How to get all the columns from CSV file

Posted in reply to siddiqalimd

How many columns do you have in the csv file?

According to your INPUT statement you get at most 5 colums.

If there are more - assign names and informats to the other columns too.

Solution
‎05-10-2017 03:57 AM
SAS Super FREQ
Posts: 708

Re: How to get all the columns from CSV file

Posted in reply to siddiqalimd

Hi

 

Why not use Proc IMPORT, like so

 

proc import
  file="/folders/myfolders/DataFiles/SuperstoreSales.csv"
  out=tableau
  dbms=csv
  replace
;
run;

Bruno

Occasional Contributor
Posts: 5

Re: How to get all the columns from CSV file

Posted in reply to Bruno_SAS
Thanks for your perfect .Blaze answer
Super User
Super User
Posts: 7,962

Re: How to get all the columns from CSV file

Posted in reply to siddiqalimd

Do bear in mind that with the simplicity of proc import, you do lose the fine grained control you had with the datastep.  For simple tasks proc import may work, but under the hood what it is doing is scanning the file and guessing what the best way to read data in.  It may/may not get this right (causing you further work), and it may not do the same thing if the data changes in any way.  Once you move from simple tasks I would really advise that you put a bit more effort into the import, write the datastep yourself (you can take the output from proc import which will be in the log and modify that to your needs), this way you know exactly how the data will import each time.  

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 4 replies
  • 153 views
  • 1 like
  • 4 in conversation