BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
LMP
Obsidian | Level 7 LMP
Obsidian | Level 7

Hello,

 

   I am trying to create age in months variable. I tried monthage=intnx('Month', DOB, sampledate) without 12 but I was getting numerical values in the hundred thousands (100,000s). Thus, I tried putting monthage= intnx('Month', DOB, sampledate, 12) because there are 12 months in a year. However, in the out put I got blanks, no errors for either runs. Please see my code below.

libname mydata "/folders/myshortcuts/myfolder";
run;

Data mydata.temp; 
set mydata.blkids2014;
/*Creating age at sampledates variables*/ 
age1=yrdif(DOB, sampledate,'ACT/ACT');
 age2=yrdif(DOB, sampledate2,'ACT/ACT');
 age3=yrdif(DOB, sampledate3,'ACT/ACT');
 age4=yrdif(DOB, sampledate4,'ACT/ACT');
 age5=yrdif(DOB, sampledate5,'ACT/ACT');
 age6 =yrdif(DOB, sampledate6,'ACT/ACT');
 age7=yrdif(DOB, sampledate7,'ACT/ACT');
 age8=yrdif(DOB, sampledate8,'ACT/ACT');
 age9=yrdif(DOB, sampledate9,'ACT/ACT');
 age10=yrdif(DOB, sampledate10,'ACT/ACT');
 age11=yrdif(DOB, sampledate11,'ACT/ACT');
 age12=yrdif(DOB, sampledate12,'ACT/ACT');
 age13=yrdif(DOB, sampledate13,'ACT/ACT');
 age14=yrdif(DOB, sampledate14,'ACT/ACT');
 age15=yrdif(DOB, sampledate15,'ACT/ACT');
 age16=yrdif(DOB, sampledate16,'ACT/ACT');
/*Creating age in months at sampledates variables*/
monthage1=intnx('Month', DOB, sampledate,12); 
monthage2=intnx('Month', DOB, sampledate2,12);
monthage3=intnx('Month', DOB, sampledate3,12);
monthage4=intnx('Month', DOB, sampledate4,12);
monthage5=intnx('Month', DOB, sampledate5,12);
monthage6=intnx('Month', DOB, sampledate6,12);
monthage7=intnx('Month', DOB, sampledate7,12);
monthage8=intnx('Month', DOB, sampledate8,12);
monthage9=intnx('Month', DOB, sampledate9,12);
monthage10=intnx('Month', DOB, sampledate10,12);
monthage11=intnx('Month', DOB, sampledate11,12);
monthage12=intnx('Month', DOB, sampledate12,12);
monthage13=intnx('Month', DOB, sampledate13,12);
monthage14=intnx('Month', DOB, sampledate14,12);
monthage15=intnx('Month', DOB, sampledate15,12);
monthage16=intnx('Month', DOB, sampledate16,12);
run;

 Does anyone have any suggestions on how I can get month age variables (like 73 months, 2 months)? 

 

 

Thanks,

 

LMP

1 ACCEPTED SOLUTION

Accepted Solutions
3 REPLIES 3
LMP
Obsidian | Level 7 LMP
Obsidian | Level 7

I tried intck instead and it worked!

ballardw
Super User

Please look at this code and see if it matches how you used intck and whether the ages are correct for your purpose.

data example;
   dob= '15JAN2015'd;
   do sampledate= '01FEB2015'd, '14FEB2015'd, '15FEB2015'd,'16FEB2015'd, 
                  '01JAN2016'd, '14JAN2016'd, '15JAN2016'd,'16JAN2016'd;
      agemonths = intck('Month', dob,sampledate);
      put dob= date9. sampledate= date9. agemonths=;
      output;
   end;
   format dob sampledate date9.;
run;

or did yours look more like:

 

data example;
   dob= '15JAN2015'd;
   do sampledate= '01FEB2015'd, '14FEB2015'd, '15FEB2015'd,'16FEB2015'd, 
                  '01JAN2016'd, '14JAN2016'd, '15JAN2016'd,'16JAN2016'd;
      agemonths = intck('Month', dob,sampledate,'continuous');
      put dob= date9. sampledate= date9. agemonths=;
      output;
   end;
   format dob sampledate date9.;
run;

BTW, you need to investigate how to use arrays.

 

LMP
Obsidian | Level 7 LMP
Obsidian | Level 7

 

Hi Ballardw,

  I didn't put specific dates because there were a variety of dates. I phrased the statement as follows: monthage=intck('Month', DOB, sampledate);

 

I hope this helps and/ or answers your question!  Thanks for the tip about arrays! I have tried it before but at the time other variables were deleted or no longer appeared. Basically, I am still working on getting arrays to work right.

 

All the Best,

 

LMP

  

 

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!

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