- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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;
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
If you watch the demos where we discuss importing Excel files using PROC IMPORT, I believe there are notes about using VALIDVARNAME=V7 so that any column names with spaces are altered to have underscores. Otherwise, you have to deal with the spaces in the column names in subsequent programs by using a different naming conventions. Because you were using VALIDVARNAME=V7, your KEEP= option needed to use the altered names, not the Excel names.
Cynthia
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Noted!
Thank you.
it worked.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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.