SAS Programming

DATA Step, Macro, Functions and more
BookmarkSubscribeRSS Feed
claremc
Obsidian | Level 7

Hello, 

 

I am importing a .csv file into SAS that has variable names like "Collection Date", "Patient Result". The variables appear the same in SAS after I import, except I can't call them because I know they actually don't have a space in their name after the import. How do I see what they actually are called? I've tried running :

options validvarname=v7

But that didn't seem to work. I tried the above with =v6, v9, and any and that didn't work. 

 

Thanks!

Clare

 

5 REPLIES 5
SurajSaini
Obsidian | Level 7
Proc contents data=Lib.dataset-name;
Run;
PaigeMiller
Diamond | Level 26

In most (all?) SAS interfaces, there is a Library/data set viewer, and as far as I know its always on the left and if you double-click on a data set in a library, you get to see (a portion of) the data and the column names that way. Scrolling will let you see all of the data and all of the column names.

--
Paige Miller
Reeza
Super User

VALIDVARNAME controls how variable names are created. V7 means it will use underscore not spaces.

You can use PROC DATASETS/CONTENTS to see variable names but you can also strip the labels off if you'd like. 

 

For a data set, CLASS, in a library called MYLIB the following will strip all labels.

proc datasets lib=mylib memtype=data;
   modify class;
     attrib _all_ label=' ';
run;
quit;

@claremc wrote:

Hello, 

 

I am importing a .csv file into SAS that has variable names like "Collection Date", "Patient Result". The variables appear the same in SAS after I import, except I can't call them because I know they actually don't have a space in their name after the import. How do I see what they actually are called? I've tried running :

options validvarname=v7

But that didn't seem to work. I tried the above with =v6, v9, and any and that didn't work. 

 

Thanks!

Clare

 


 

ballardw
Super User

The Validvarname=V7 means that characters not valid in SAS names will be replaced with _ characters as opposed to Validvarname=Any which would allow spaces and other characters. However you would then have to use name-literals in the code: 'Collection Date'n evertime to use the variable.

 

When you run proc import data step code is generated and appears in the log with the names of the variables in INFORMAT, FORMAT and INPUT statements.

 

Here's an idea: write a data step to change the names to what you like. You can copy that generated code and replace "Collection_Date" with "CollectionDate" if that is what you would prefer.

 

A very useful side effect of modifying the code is that you can set standard lengths/ types for other files of the same structure. Just change the Infile statement to point to a new file and change the name of Data set  for output.

Then you will avoid all the problems associated with mismatched variable types or lengths of character variables.

 

Astounding
PROC Star

If these really are the variable names, you can refer to them in your subsequent programming using:

 

"Collection date"n

 

The n after the closed quote indicates that this is a name, not a character string in quotes.

 

The option you used:

 

validvarname=v7;

 

will work, but you need that option in place before you import the data, not after.

sas-innovate-white.png

Our biggest data and AI event of the year.

Don’t miss the livestream kicking off May 7. It’s free. It’s easy. And it’s the best seat in the house.

Join us virtually with our complimentary SAS Innovate Digital Pass. Watch live or on-demand in multiple languages, with translations available to help you get the most out of every session.

 

Register now!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 5 replies
  • 9555 views
  • 2 likes
  • 6 in conversation