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 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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