BookmarkSubscribeRSS Feed
Sir_Highbury
Quartz | Level 8

Dear SAS experts,

 

which ist the easiest way to import a csv specifying:

- in wich row are the headers

- in which row start the data

 

I tried in several ways (dataeow, firstobs...) But I do not gest what i want.

for instance:

proc import datafile='test.csv'

  datarow=3; getnames=yes;

run;

 

Attached an example of the csv input and the data that I would like to get in SAS.

5 REPLIES 5
ballardw
Super User

Reading variable names from the CSV requires that the name be on a single row. Easiest is to Edit the CSV to remove the entire first line with the column headers like "Platin/EURO".

Then datarow=2 should work fine.

Sir_Highbury
Quartz | Level 8

Hi ballardw,

thank but this is what I am currently doing and I would not.

So means that SAS cannot do it?

data_null__
Jade | Level 19

Use a data step to write a new copy of the file with the record(s) edited as you see fit.  Then run your PROC IMPORT on that.

ballardw
Super User

@Sir_Highbury wrote:

Hi ballardw,

thank but this is what I am currently doing and I would not.

So means that SAS cannot do it?


Show the exact code you run, the Log results and  show the data as a TXT file not Excel (it may change values with out telling you).

 

You should always use a fully qualified path to point to input and out file locations : datafile = "C:\somefolder\otherfolder\inputfile.csv" for example instead of  datafile="test.csv" as the later is going to read from what SAS considers the current active folder and is very likely not the location you expect.

Tom
Super User Tom
Super User

For a file with three variable just write the data step yourself.  Probably will take less code than the the PROC IMPORT statements.

data want ;
   infile "myfile.csv" dsd firstobs=3 truncover ;
   length date field1 field2 8 ;
   informat date mmddyy10.;
   format date yymmdd10.;
   input date field1 field2;
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
  • 5 replies
  • 16519 views
  • 1 like
  • 4 in conversation