BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
CathyVI
Pyrite | Level 9

Hi,

I have a sas dataset that has some variables that was not presenting frequencies. The variables are named and label like this;  U-METHADONE, U-OXY, U-FENTANYL.

How can I resolve this problem.

 

proc freq data = original_data;
tables U-METHADONE;
run;

*LOG;

1 OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;
68
69 proc freq data = original_data;
70 tables U-METHADONE;
ERROR: Variable U not found.
71 run;

I have attempted to rename the variables but no luck.

data new_data;
set original_data (rename=(U-METHADONE=Methadone));
keep Methadone ;
run;

*LOG;

69 data new_data;
70 set stcp.cleanedpracticum2(rename=(U-METHADONE=Methadone));
ERROR: U does not have a numeric suffix.
71 keep Methadone;
72 run;

Thanks

 

1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26

Variable names cannot have a dash (hyphen) in the variable name.

 

You can override this with the following option:

 

options validvarname=any;

and then you can refer to variables in your code with dash in their name as, for example,

 

tables 'U-METHADONE'n;

 

--
Paige Miller

View solution in original post

5 REPLIES 5
PaigeMiller
Diamond | Level 26

Variable names cannot have a dash (hyphen) in the variable name.

 

You can override this with the following option:

 

options validvarname=any;

and then you can refer to variables in your code with dash in their name as, for example,

 

tables 'U-METHADONE'n;

 

--
Paige Miller
Tom
Super User Tom
Super User

Hyphens are not allowed in valid variable names.  It thinks you are trying to do some type of variable list, but the syntax is not right for that either as for a variable list using a single hyphen you need names with a numeric suffix.

 

If you have the validvarname option set to ANY (why?) then you need to use a Name Literal to reference a variable name that does not follow normal naming rules.

tables "U-METHADONE"n;

Otherwise if you have validvarname=v7 then you are probably trying to use the LABEL of the variable where you should be using the NAME of the variable.

PaigeMiller
Diamond | Level 26

Show us the output of PROC CONTENTS on this data set for these variables.

--
Paige Miller
CathyVI
Pyrite | Level 9

Thank you. The problem is solved. I still sent you a snippet of the proc content if you still need it.

 

CathyVI_0-1655131124784.png

 

PaigeMiller
Diamond | Level 26

Thanks! But as long as the problem is solved, the PROC CONTENTS is no longer needed.

--
Paige Miller

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 521 views
  • 0 likes
  • 3 in conversation