BookmarkSubscribeRSS Feed
Lost_Gary
Quartz | Level 8

I am using data from multiple sources that is not consistent.  This source furnishes information in Excel format.  Because my variable names are not universal I have been using the Validvarname option to import the data (using proc import, getnames=yes).  For some fields this returns a generic value, such as VAR1, VAR2, etc.  Is there anyway to get this to return a value?  

 

For instances, I have a variable called "Sample".  One source has listed this as "Sample (Y/N)".  This returns the generic value of VAR15 and I would like some form of the word "Sample" so i can understand the content.    

 

Any ideas are appreciated.  

Thanks

5 REPLIES 5
SuryaKiran
Meteorite | Level 14

Hello,

 

Validvarname=any option should read your column names that have special characters.

 

options validvarname=any;
Thanks,
Suryakiran
Tom
Super User Tom
Super User

Why not just look at the LABEL on the variable? 

PROC IMPORT from an XLSX file should put the original header value into the LABEL no matter what setting you have for the VALIDVARNAME option.

 

image.png

Reeza
Super User

Are the tables generally the same? Is there an option to convert, in batch, to csv and then read those in with the desired specifications. 

 

If so, here's a vb script that will convert all files in a folder from xlsx to csv. 

https://gist.github.com/statgeek/878e585102c14e01581f55dbe972d27e

 


@Lost_Gary wrote:

I am using data from multiple sources that is not consistent.  This source furnishes information in Excel format.  Because my variable names are not universal I have been using the Validvarname option to import the data (using proc import, getnames=yes).  For some fields this returns a generic value, such as VAR1, VAR2, etc.  Is there anyway to get this to return a value?  

 

For instances, I have a variable called "Sample".  One source has listed this as "Sample (Y/N)".  This returns the generic value of VAR15 and I would like some form of the word "Sample" so i can understand the content.    

 

Any ideas are appreciated.  

Thanks


 

Lost_Gary
Quartz | Level 8

so the validvarname = any will pull the data into a dataset, but I can't call that data field based on the name "Sample (Y/N)" as that wouldn't be valid.  Obviously the next move I want to make is an if statement such as If Sample = 'Y' then ........

 

Unfortunately, the data is probably not consistent enough to simply switch to a csv, plus there is need for me to pull data from different sheets within each workbook.  

 

 

ChrisNZ
Tourmaline | Level 20

> I can't call that data field based on the name "Sample (Y/N)" 

 

You can.

You have to use the string suffix n.

 

The best way to use it is generally in a rename statement/option so you don't carry these silly names in your program.

rename 'Sample (Y/N)'n = SAMPLE;

 

Then set option validvarname back to V7.

SAS Innovate 2025: Call for Content

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 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 5 replies
  • 961 views
  • 2 likes
  • 5 in conversation