BookmarkSubscribeRSS Feed
SelenaR
Calcite | Level 5

I am getting the following errors when trying to run a Chi-square.

 
 

SelenaR_2-1739053571440.png

SelenaR_3-1739053627319.png

please help

 

2 REPLIES 2
Ksharp
Super User
It appeared that you don't have variables "Htn_dx" and "DMII_dx" in dataset "hrthlth.pbh510" .
Using the following code to check all the variables in your datset.


proc contents data=hrthlth.pbh510 varnum;
run;



Tom
Super User Tom
Super User

It is very hard to tell what is happening by looking a photographs.  Especially ones of text displayed with proportionally spaced fonts.

 

Double check the names of the variables (and the dataset and the libref) to make sure that the names in your code actual match the names the dataset.

 

Run PROC CONTENTS on the dataset.   If that fails the run then you have libref or member name wrong in your code.

 

But even if it runs and you just look at the printout you might be fooled by the proportional spacing into not seeing leading spaces or other invisible characters in the variable names.

 

So better is to use the OUT= option of PROC CONTENTS to make a dataset with the names and look carefully at the names.   

 

Use code like this:

proc content data=mylib.mydataset out=contents ;
run;

proc print data=contents;
  var varnum name ;
  format name $quote.;
run;

To see what you might be missing try running this example:

options varvarname=any;
data class;
  set sashelp.class;
  rename name=' Name'n;
run;
proc contents data=class out=contents; run;
proc print data=contents;
  var varnum name;
  formt name $quote.;
run;

Results:

Screenshot 2025-02-09 at 3.17.06 PM.png

Why does NAME come before AGE in the alphabetical listing from PROC CONTENTS?

Then answer is that the variable's name actually has a leading space, which you can see when the value is printed with the $QUOTE format.

To reference a variable with a leading sapce (or other strange names) use a NAME LITERAL, like was used in the RENAME statement in the example code.

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

SAS Training: Just a Click Away

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

Browse our catalog!

Discussion stats
  • 2 replies
  • 770 views
  • 1 like
  • 3 in conversation