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
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.
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
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.
What is the source of the names. Are they in another file? Perhaps with other useful meta data like type, informat and description(label).
Create a fileref to concatenate the two files and use PROC IMPORT
FILENAME BOTH ('var-name.csv','data.csv');
PROC IMPORT DATAFILE=BOTH ...
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 16. Read more here about why you should contribute and what is in it for you!
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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: