i am completely new to programming and a beginner to sas learning.
how to write keep or drop option in proc import while importing an excel file when it has spaces in the column names of its excel sheet
the following are the program that i wrote and the log warning.
options validvarname=v7;
proc import
datafile= '/home/u43101927/EPG194/Data/np_info.xlsx' out=species (keep=Park Name Category Scientific Name Common Names)
dbms=xlsx replace;
sheet="species";
getnames=yes;
run;
This option has taken care of the spaces in the column names by replacing with the Underscores , which is apparent in the log :
options validvarname=v7;
Just modify your keep list accordingly :
proc import
datafile= '/home/u43101927/EPG194/Data/np_info.xlsx' out=species (keep=Park_Name Category Scientific_Name Common_Names)
dbms=xlsx replace;
sheet="species";
getnames=yes;
run;
This option has taken care of the spaces in the column names by replacing with the Underscores , which is apparent in the log :
options validvarname=v7;
Just modify your keep list accordingly :
proc import
datafile= '/home/u43101927/EPG194/Data/np_info.xlsx' out=species (keep=Park_Name Category Scientific_Name Common_Names)
dbms=xlsx replace;
sheet="species";
getnames=yes;
run;
believe me, i spent about an hour working on this with different possibilities including that underscore in the variable name also. it didn't worked out then.
but this time it worked fine! i might have done some other possible mistake!
it worked. thanks.
Note the nice thing that SAS is doing for you by converting the nonstandard names (with blanks) to standard names (with underlines); use those standard names in the keep= option.
Noted!
Thank you.
it worked.
The SAS system is pretty nice with some things. One is that when you substitution like that in the log then you can click on the replace name, copy and paste into the editor.
The obnoxious files where the column headers exceed 32 characters and have the same first 32 characters are not so nice as SAS will give you VARxx where XX is the column number.
Or when the column heading is repeated. You may have some finding out which of Total, Total12, Total18, Total21 (or more) that you actually want for a given purpose.
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.
Ready to level-up your skills? Choose your own adventure.