DATA Step, Macro, Functions and more

Provided Headers vs. Provided Dataset without Headers

Reply
Super Contributor
Posts: 312

Provided Headers vs. Provided Dataset without Headers

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

 

Super User
Posts: 17,912

Re: Provided Headers vs. Provided Dataset without Headers

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. 

Super Contributor
Posts: 312

Re: Provided Headers vs. Provided Dataset without Headers

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

Super User
Posts: 17,912

Re: Provided Headers vs. Provided Dataset without Headers

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. 

Respected Advisor
Posts: 3,777

Re: Provided Headers vs. Provided Dataset without Headers

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

Super Contributor
Posts: 312

Re: Provided Headers vs. Provided Dataset without Headers

The variable names are stored in another csv file, only one row. There are 28 variables (I only showed 9 above to save space).
Respected Advisor
Posts: 3,777

Re: Provided Headers vs. Provided Dataset without Headers

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

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

 

Ask a Question
Discussion stats
  • 6 replies
  • 258 views
  • 5 likes
  • 3 in conversation