How to retrieve data at different times?

Reply
N/A
Posts: 0

How to retrieve data at different times?

Hello!

I am having problems with the following in SAS:
I am investigating the association between parents marital status and childrens health status. I am investigating this in the time period of 1990-2005.
I can get information about parental marital status once every year - on Jan 1.
I can get information about the children continously.

So, in order to be as precise as possible, I would like to do the following:

If the child is born between Jan 1 and June 30 2000 (e.g) the information about parental marital status should be drawn on Jan 1 2000.

If the child is born between Jul 1 and December 31 2000 the information about parental marital status should be drawn on Jan 1 2001.

How can I do this in SAS?

Kind regards, Grethe
SAS Employee
Posts: 170

Re: How to retrieve data at different times?

You can test your conditions with IF staements or using SAS functions

data test;
date='1jan09'd;
date0=intnx('year',intnx('month',date,6),0);
put (_all_) (= date.);
date='1jul09'd;
date0=intnx('year',intnx('month',date,6),0);
put (_all_) (= date.);
run;
Super Contributor
Super Contributor
Posts: 3,174

Re: How to retrieve data at different times?

Also, you might find interest in using the MONTH function to test the month-of-year values 1-6 and set your some_important_date using INTNX with 'year' (not month as shown) with the third argument of 0 -- otherwise you would use a third argument of 1 (again with 'year') to increment to the next year's start-date.

Scott Barry
SBBWorks, Inc.

data _null_;
format mybirthdate someotherdate date9.;
mybirthdate = '01aug2000'd;
if month(mybirthdate) le 6 then someotherdate = intnx('year',mybirthdate,0);
else someotherdate = intnx('year',mybirthdate,1);
putlog _all_;
run;
N/A
Posts: 0

Re: How to retrieve data at different times?

Thank you - both of you - for your responses!
That was a big help.

However, I have faced a new problem and need som help again.

I am working with some variables, that have quite long names. The names of the variables are made out of numbers, and I only want to use the first two numbers in the variable name, when I run the analyses. How can i do that?

I have tried to write: temp_1=(substr(variablename,1,2);

but it doesnt seem to work. What am i doing wrong?

Thank you!
Super Contributor
Super Contributor
Posts: 3,174

Re: How to retrieve data at different times?

It is most suitable and considerate to forum visitors if you open a new post when you have a new question/concern.

Scott Barry
SBBWorks, Inc.
Super Contributor
Super Contributor
Posts: 3,174

Re: How to retrieve data at different times?

Also, you need only submit an item in a single forum, not multiple for a given post.
Super Contributor
Super Contributor
Posts: 3,174

Re: How to retrieve data at different times?

Refer to duplicate post and reply here:

http://support.sas.com/forums/thread.jspa?threadID=5956&tstart=0


Scott Barry
SBBWorks, Inc.
Ask a Question
Discussion stats
  • 6 replies
  • 524 views
  • 0 likes
  • 3 in conversation