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);
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?
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!
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.
You can do the selection much easier before you transpose to the wide layout.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.