BookmarkSubscribeRSS Feed
fengyuwuzu
Pyrite | Level 9

my csv file has no header info. Data starts from row 1.

when I imported to SAS, they were named var1 var2 var3, etc.

 

I want to change the names to their real variable names. I can rdit the CSV file, insert a line on top of the data rows, and enter variables there. This runs fine.

 

can I do another way, that I do not touch the original csv file, but add variable names in importing (data step using infile)?

 

Thanks

 

6 REPLIES 6
Reeza
Super User

Yes, you specify the variables in your input statement. I'm assuming you used proc import to import the data?

You can check the log for the code, copy it and customize it as desired, ie appropriate formats, names. 

fengyuwuzu
Pyrite | Level 9

the log has the code like this:

 

       informat VAR1 yymmdd10. ;
       informat VAR2 $40. ;
       informat VAR3 best32. ;
       informat VAR4 best32. ;
       informat VAR5 best32. ;
       informat VAR6 best32. ;
       informat VAR7 $19. ;
       informat VAR8 $19. ;
       informat VAR9 $19. ;
       format VAR1 yymmdd10. ;
       format VAR2 $40. ;
       format VAR3 best12. ;
       format VAR4 best12. ;
       format VAR5 best12. ;
       format VAR6 best12. ;
       format VAR7 $19. ;
       format VAR8 $19. ;
       format VAR9 $19. ;
    input
                VAR1
                VAR2 $
                VAR3
                VAR4
                VAR5
                VAR6
                VAR7 $
                VAR8 $
                VAR9 $

;

 

shall I replace only VAR1-9 in input, or all of them (informat, format, input)?  Thanks

Reeza
Super User

You need to make the changes everywhere.

 

ie if you're renaming VAR1=CARS you need to replace it everywhere VAR1 appears. You may also want to confirm that they're what you want. 

data_null__
Jade | Level 19

What is the source of the names.  Are they in another file?  Perhaps with other useful meta data like type, informat and description(label).

fengyuwuzu
Pyrite | Level 9
The variable names are stored in another csv file, only one row. There are 28 variables (I only showed 9 above to save space).
data_null__
Jade | Level 19

Create a fileref to concatenate the two files and use PROC IMPORT

FILENAME BOTH ('var-name.csv','data.csv');
PROC IMPORT DATAFILE=BOTH ...

 

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