BookmarkSubscribeRSS Feed
bhufman
Calcite | Level 5

In the program I am working on I am looking to have 573 observations after everything is merged, however I am either coming up with 598 or 0, and the variable Age is also dropping.

 

Here is my code:


Proc contents Data= Hyptabs.vitals;

Run;

Data Work.lastvitals;
Set Hyptabs.vitals;
By SSN;
IF Last.SSN= 1;
Run;

Data Hypanl.Hypanalysis2;
Retain SSN StateCd
GenderCd EthCd RaceCd AgeAtVisit
SBP DBP WtLb
HypRelDeathInd;

Merge HypTabs.Demog (IN = InDemog Drop = EthRaceCd)
Hyptabs.Contact (IN= InContact Keep= SSN StateCd)
Work.LastVitals (IN = InLastVitals Drop= HtIN)
Hyptabs.NDI (IN= INNDI Drop=Deathdt ICD10 CODCD);

By SSN;
IF Incontact=1 AND
InDemogs = 1 AND
InVitals = 1;

If Indvbl = . THEN Hypre1DeathInd = 0;
Else IF Indvbl = 0 THEN HypReIDeathInd= 0;
ELSE IF IndVbl = 1 THEN HypRelDeathInd = 1;

AgeAtVisit1 = YRDIF(BirthDt, VisitDt, 'AGEAtvisit');
FORMAT AgeAtVisit 2.0;

DROP BirthDt VisitDt;
Run;
Proc Print Data=Hypanl.hypanalysis2;
Run;

 

 

One of the things that the log is saying that I'm really not sure about is the log saying this: 

NOTE: Variable AgeAtVisit is uninitialized.
NOTE: Variable InDemogs is uninitialized.
NOTE: Variable InVitals is uninitialized.
NOTE: Variable Indvbl is uninitialized.
What does that mean, and is that where my problem lies?
4 REPLIES 4
ballardw
Super User

Easy part first:

 

One of the things that the log is saying that I'm really not sure about is this: 

NOTE: Variable AgeAtVisit is uninitialized.
NOTE: Variable InDemogs is uninitialized.
NOTE: Variable InVitals is uninitialized.
NOTE: Variable Indvbl is uninitialized.

This occurs when you use a variable name that has no values.

 

Likely cause for some spelling:

 

Merge HypTabs.Demog (IN = InDemog Drop = EthRaceCd)
Hyptabs.Contact (IN= InContact Keep= SSN StateCd)
Work.LastVitals (IN = InLastVitals Drop= HtIN)
Hyptabs.NDI (IN= INNDI Drop=Deathdt ICD10 CODCD);

By SSN;
IF Incontact=1 AND
InDemogs = 1 AND
InVitals = 1;

If Indvbl = . THEN Hypre1DeathInd = 0;
Else IF Indvbl = 0 THEN HypReIDeathInd= 0;
ELSE IF IndVbl = 1 THEN HypRelDeathInd = 1;

Your Retain and Format AgeAtVisit, you assign a value to AgeAtVisit1. If AgeAtVisit is NOT in one of the data sets, which it isn't because you did not KEEP it, then there is no value and causes the note for that variable. BTW you are getting luck with the YRDIF function. It is default to "AGE" as the basis. AgeAtVisit is not a valid basis value. Sort of surprised you don't get a warning or error from that use.

 

The only place Indvbl appears is in those If statements. It is not a variable kept from one of the sets and is not the name of one of the IN= created variables. From the other spellling errors I suspect it was intended.

 

When asking questions about why you don't get an expected number of observations as a minimum you should include the entire log with ALL the notes, warnings and such. That will tell us how many records each of the contributing data sets brings in.

 

You have a subsetting IF that can never be true because of two variables misspelled. So that would be the main cause for getting 0 observations:

IF Incontact=1 AND
InDemogs = 1 AND
InVitals = 1;

You have a

Merge BY SSN;

HyTabs.Contact is the only data set shown with the SSN variable. So does your code throw a number of ERRORS about missing BY variables.

 

Now for the fun part.

Why do you think there should be 573 observations? Is that the number of one of the sets? If so, which one?

 

 

 

Cooksam13
Fluorite | Level 6

My understanding is that the Drop and keep statements could be throwing off the code. the items you are dropping and keeping will do what you want by merging them, there will not be an "excess" of information that you need to make sure is kept or dropped. 

DATA	Analysis;
MERGE Vitals (In = INVitals)
Demog (In = INDemog)
Contact (In = INContact)
NDI (In = InDeathDt);
BY SSN;
If last.SSN ;
If InVitals = 1 AND
InDemog = 1 And
InContact = 1;
If HypRelDeathInd = '.' Then HypRelDeathInd = 0;

 

haileyhw
Calcite | Level 5

Looks like others have helped you with most of the errors, but the reason you are getting the Indvbl error is because that is a format, not a variable. 

The code you want looks like this:

IF HypRelDeathInd = '.' THEN HypRelDeathInd = 0;

FORMAT HypRelDeathInd IndVbl.;

Hope this helps!

mdakkak
Fluorite | Level 6

Hi,

 

I was running into a similar issue. I think here is where it lies. 

 

InVitals = 1;

If Indvbl = . THEN Hypre1DeathInd = 0;
Else IF Indvbl = 0 THEN HypReIDeathInd= 0;
ELSE IF IndVbl = 1 THEN HypRelDeathInd = 1;

 

Since your code is referring to lastvitals, the InVitals = 1, needs to be changed to InLastVitals = 1. Then the IndVbl is a format not a variable. Should be like this: FORMAT HypRelDeathInd IndVbl.

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 4 replies
  • 851 views
  • 1 like
  • 5 in conversation