BookmarkSubscribeRSS Feed
anilgvdbm
Quartz | Level 8

Dear Friends,

when i run the belowed code

data want.BMI_women;

set have.BMI_women;

if  Women_BMI le 16.00  then bmi="Severe thinness";

else if Women_BMI le 16.99    then  bmi="Moderate thinness";

else if Women_BMI le 18.49    then  bmi="Mild thinness";

else if Women_BMI le 24.99    then  bmi="Normal range";

else if Women_BMI le 29.99    then  bmi="Overweight";

else if Women_BMI le 34.99    then  bmi="Obese class I";

else if Women_BMI le 39.99    then  bmi="Obese class II";

else if Women_BMI ge 40.00    then  bmi="Obese class III";run;

i am getting an error message like this

384  data nfhs_3.BMI_women;

385  set nfhs_3.BMI_women;

386  length bmi $20;

387  if  Women_BMI le 16.00  then bmi="Severe thinness";

388  else if Women_BMI le 16.99  then  bmi="Moderate thinness";

389  else if Women_BMI le 18.49  then  bmi="Mild thinness";

ERROR: The name  bmi is not a valid SAS name.

390  else if Women_BMI le 24.99  then  bmi="Normal range";

ERROR: The name  bmi is not a valid SAS name.

391  else if Women_BMI le 29.99  then  bmi="Overweight";

392  else if Women_BMI le 34.99  then  bmi="Obese class I";

393  else if Women_BMI le 39.99  then  bmi="Obese class II";

394  else if Women_BMI ge 40.00  then  bmi="Obese class III";

395  run;

i tried a lot for this but i didnt get the solution please help me out in this.

Thanks

Anil

20 REPLIES 20
mohamed_zaki
Barite | Level 11

I have tried your code and it work for me with no error

data BMI_women;

input Women_BMI ;

datalines;

20.22

5

6

34.33

50

-22.5

;

data BMI_women_new;

set BMI_women;

length bmi $25;

if  Women_BMI le 16.00  then bmi="Severe thinness";

else if Women_BMI le 16.99  then  bmi="Moderate thinness";

else if Women_BMI le 18.49  then  bmi="Mild thinness";

else if Women_BMI le 24.99  then  bmi="Normal range";

else if Women_BMI le 29.99  then  bmi="Overweight";

else if Women_BMI le 34.99  then  bmi="Obese class I";

else if Women_BMI le 39.99  then  bmi="Obese class II";

else if Women_BMI ge 40.00  then  bmi="Obese class III";

run;

try run the code above and see if you will get the same error

Reeza
Super User

The code you've shown and the log don't match...the first references want.bmi_women and the log references nfhi_s.bmi_women.

You're writing the data back to the same data set which can cause errors, try writing it to a new data set.

Tom
Super User Tom
Super User

The only thing that I think that would produce a log like that would be if there are strange characters in your file so that what looks like "bmi" in the program either includes some hidden character or they are not actually the characters B, M and I.

For example if you type program code into WORD it might convert your quotes and hyphens to some other character that it thinks looks better.  If you then try to run the program in SAS it will be confused by these non standard characters.

anilgvdbm
Quartz | Level 8

Hi Tom and Reeza ,

Thanks for comenting even i changed the dataset name and variables names but still i am getting same error. I am totaly confused about this i wrote this type of codes earlier also. Bur i am not able to find out the error. Please clarify me where i habe done mistake? this code i have to apply for many files i mean i habe to apply macros here.

Waiting for your answers

Thanks a lot

Anil

Tom
Super User Tom
Super User

Can you paste in the actual characters from the SAS log?

anilgvdbm
Quartz | Level 8

27   data nfhs_3.want;

28   set nfhs_3.BMI_women;

29   if  Women_BMI le 16.00  then bmi="Severe thinness";

30   else if Women_BMI le 16.99  then  bmi="Moderate thinness";

31   else if Women_BMI le 18.49  then  bmi="Mild thinness";

ERROR: The name  bmi is not a valid SAS name.

32   else if Women_BMI le 24.99  then  bmi="Normal range";

ERROR: The name  bmi is not a valid SAS name.

33   else if Women_BMI le 29.99  then  bmi="Overweight";

34   else if Women_BMI le 34.99  then  bmi="Obese class I";

35   else if Women_BMI le 39.99  then  bmi="Obese class II";

36   else if Women_BMI ge 40.00  then  bmi="Obese class III";

37   run;

NOTE: The SAS System stopped processing this step because of errors.

WARNING: The data set NFHS_3.WANT may be incomplete.  When this step was stopped there were 0

         observations and 119 variables.

NOTE: DATA statement used (Total process time):

      real time           0.37 seconds

      cpu time            0.00 seconds

mohamed_zaki
Barite | Level 11

When you run your code with other data sets (Any random created data set). Does you get the same Error?

Waiting for your answer...

anilgvdbm
Quartz | Level 8

Hi Mohamed,

No i tried with other dataset i am not getting error even in the above codes when i will give run up to "moderate thinness" it will run. But i am getting only 3rd and 4th line of the codes is getting error.

Thanks

Anil

mohamed_zaki
Barite | Level 11

Do you mean that with your current data set if your code is as following

data nfhs_3.want;

set nfhs_3.BMI_women;

if  Women_BMI le 16.00  then bmi="Severe thinness";

else if Women_BMI le 16.99  then  bmi="Moderate thinness";

run;

without the rest of the if-then conditions, your program complete successfully (with out error, i mean).

Waiting for your answer...

Reeza
Super User

post a proc contents from your input data set.

Tom
Super User Tom
Super User

So there is nothing in the code that you have pasted that could generate the error you posted.  But perhaps the code you are running does not really look like what you posted.   Try copying your code and modifying as I have done below and see if you still get the error messages.  If that makes the error message go away then perhaps the error messages are not about your code but are about your input data set.

3754  data want;

3755  *  set nfhs_3.BMI_women;

3756    if  Women_BMI le 16.00  then bmi="Severe thinness";

3757    else if Women_BMI le 16.99  then  bmi="Moderate thinness";

3758    else if Women_BMI le 18.49  then  bmi="Mild thinness";

3759    else if Women_BMI le 24.99  then  bmi="Normal range";

3760    else if Women_BMI le 29.99  then  bmi="Overweight";

3761    else if Women_BMI le 34.99  then  bmi="Obese class I";

3762    else if Women_BMI le 39.99  then  bmi="Obese class II";

3763    else if Women_BMI ge 40.00  then  bmi="Obese class III";

3764  run;

NOTE: Variable Women_BMI is uninitialized.

NOTE: The data set WORK.WANT has 1 observations and 2 variables.

- Can you re-type the program?

- Can you read the program as data and check the characters.

data _null_;

  infile 'mycode.sas' ;

  input;

  list;

run;

damanaulakh88
Obsidian | Level 7

HI Anil,

The following error message might appear when you open a SAS data set with Base SAS that was created with SAS Enterprise Guide:

 

The problem occurs because the VALIDVARNAME=ANY system option is the default in SAS Enterprise Guide, but VALIDVARNAME=V7 is the default in Base SAS. This means that variable names containing special characters such as the hyphen character or other characters can be created with SAS Enterprise Guide.

To overcome the problem, specify the following OPTIONS statement when you open these data sets with Base SAS:

options validvarname=any;

Thanks,

Daman

anilgvdbm
Quartz | Level 8

Hi Daman,

its working but its creating 2 variables with the same name half of the values are in one variable and half of the values in another  variable. i attache screen shot for you.

Thanks and Regards,

Anil

damanaulakh88
Obsidian | Level 7

Where are the screen shots?

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

How to choose a machine learning algorithm

Use this tutorial as a handy guide to weigh the pros and cons of these commonly used machine learning algorithms.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 20 replies
  • 2396 views
  • 3 likes
  • 8 in conversation