Home > database >  Importing data from excel to SAS
Importing data from excel to SAS

Time:09-22

One interview question--I didn't get answer of this, please help me to solve this.

In excel file variable name having space in between (e.g- Shop Name), if we will bring excel data to the sas. How we will bring as it is, bcz in sas dataset, space is not allowed between the variable name?

Code:

proc import datafile='/home/roshnigupta16020/test (2).xlsx' out=testexcel dbms=xlsx replace; getnames=yes; run;

CodePudding user response:

Your PROC IMPORT syntax is good.

proc import datafile='/home/roshnigupta16020/test (2).xlsx' 
  out=testexcel dbms=xlsx replace
; 
  getnames=yes; 
run;

Depending on the setting of the VALIDVARNAME option PROC IMPORT will create different names for the variables.

With VALIDVARNAME=ANY the names will include the spaces. Which means that to use the name in your SAS code you will need to use name literals, like 'Column 1'n.

With other settings, like VALIDVARNAME=V7, then PROC IMPORT will replace invalid characters, like spaces, with underscores. Then the name will not exactly match the column header in the spreadsheet. But the name will be something like Column_1 which is easier to include in your SAS code.

  • Related