BookmarkSubscribeRSS Feed
gejoachim99
Fluorite | Level 6

I have an age variable and I would like to run an analysis only on 0-35 years of that variable. I want to include people who have an input of 40, for example, but only on the data for 0-35 for that person. I want to include that in some code that I already have, in which I am calculating the duration of smoking over a lifetime. I basically just want to limit it to exposure that happened before age 35. I have variables, hashlage1-4, which represent the last age of different periods of smoking throughout a lifetime. I'm not sure how (or if) I should use this variable, or if there is another way to set a maximum. I hope this makes sense. Thanks.

 

/*duration*/
data work.adenovar;
set work.adeno1;
if hashtot >= 1 and hashtot < =4 and hashfage1 ^= 99 and hashlage1 ^= 99 then hashdur1 = (hashlage1-hashfage1)+1;
if hashtot >= 2 and hashtot <= 4 and hashfage2 ^= 99 and hashlage1 ^= 99 then hashdur2 = (hashlage2-hashfage2)+1;
if hashtot >= 3 and hashtot <= 4 and hashfage3 ^= 99 and hashlage1 ^= 99 then hashdur3 = (hashlage3-hashfage3)+1;
else if hashtot = 4 and hashfage4 ^= 99 and hashlage4 ^= 99 then hashdur4 = (hashlage4-hashfage4)+1;

/*total duration*/
hashdurtot = sum(of hashdur1-hashdur4);

4 REPLIES 4
ballardw
Super User

What are the actual values of the variables? Which variable is "exposure"? Age? Which age?

 

I am afraid that you really need to show some values and probably worked example results done by age.

 

Are asking how to use this or create a variable?

gejoachim99
Fluorite | Level 6

hashlage1-4 is the last age they smoked at for a given time period. hashlage1-4 is the first age. hashtot is indicating the number of smoking episodes they had. In the code that I pasted in, I'm just creating a duration variable, so last age - first age (plus 1 so I didn't have anyone with a '0' in case they started and stopped within the same year), then adding together that number (the number of years smoked) for each time period that they were smokers (say if they smoked from 18 to 24, then stopped, then started again from 30-37, they would have two time periods). What I want to do is limit my analysis to only the data before they were 35 years old. So, using the example I just gave, I want to exclude the two years after age 35, and only include their data from age 18 to age 35 (even though they continued to smoke after age 35). My outcome is related to early life exposure, which is why I'm trying to do this, and the exposure is smoking. Let me know if you need some more information. Thanks!

Kurt_Bremser
Super User

With a proper layout, it's this:

data select;
set have;
where hashfage le 35;
hashlage = min(hashlage,35);
hashdur = hashlage - hashfage + 1;
run;

Now you can count and summarize.

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

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
  • 4 replies
  • 901 views
  • 0 likes
  • 3 in conversation