BookmarkSubscribeRSS Feed
thanikondharish
Fluorite | Level 6

thanikondharish_0-1615543551389.png

I have one csv file path is 'D:\Parc\file_dump.csv'  and we have to take 2nd row as column names.

Note: dont delete first row.

5 REPLIES 5
Ksharp
Super User
How do you import this CSV file ?
data step or PROC IMPORT ( try option : datarow=3 )
thanikondharish
Fluorite | Level 6
Proc import only and datarow option is like data starting record but this
option won't use for column names
Ksharp
Super User

Delete the first line ?

 

filename x temp;
data _null_;
 infile 'c:\temp\root.csv' lrecl=32767;
 input;
 file x ;
 if not missing(_infile_) then put _infile_ ;
run;

proc import datafile=x out=x dbms=csv replace;
getnames=yes;
guessingrows=max;
run;
Ksharp
Super User

Or rename it after importing ?

 

proc import datafile='c:\temp\root.csv' out=data dbms=csv replace;
datarows=3;
guessingrows=max;
run;


options obs=2;
proc import datafile='c:\temp\root.csv' out=vname dbms=csv replace;
run;
options obs=max;

proc transpose data=vname out=vname2;
var _all_;
run;

proc sql noprint;
select catt(_name_,'=',col1) into :rename separated by ' ' from vname2;
quit;

proc datasets library=work nolist nodetails;
modify data;
rename &rename. ;
quit;

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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
  • 5 replies
  • 4877 views
  • 0 likes
  • 3 in conversation