05-02-2024
gabagotati
Calcite | Level 5
Member since
08-24-2022
- 10 Posts
- 0 Likes Given
- 0 Solutions
- 0 Likes Received
-
Latest posts by gabagotati
Subject Views Posted 1085 03-28-2024 04:16 PM 824 01-06-2023 05:13 PM 853 01-06-2023 04:53 PM 1243 09-19-2022 01:36 PM 1276 09-19-2022 12:13 PM 1569 08-24-2022 02:43 PM 1591 08-24-2022 02:06 PM 1650 08-24-2022 12:03 PM -
Activity Feed for gabagotati
- Posted Count number of days within a span in a given year on SAS Programming. 03-28-2024 04:16 PM
- Posted Re: Appending specific year to an extracted month and day on SAS Programming. 01-06-2023 05:13 PM
- Posted Appending specific year to an extracted month and day on SAS Programming. 01-06-2023 04:53 PM
- Posted Re: Search columns for match in string from other table on SAS Programming. 09-19-2022 01:36 PM
- Posted Search columns for match in string from other table on SAS Programming. 09-19-2022 12:13 PM
- Posted Re: Retaining max values over multiple columns on SAS Programming. 08-24-2022 02:43 PM
- Posted Re: Retaining max values over multiple columns on SAS Programming. 08-24-2022 02:06 PM
- Posted Retaining max values over multiple columns on SAS Programming. 08-24-2022 12:03 PM
03-31-2024
11:22 PM
It's with SAS data steps and especially SAS proc's often easier to work with narrow data structures. That's what below code creates.
data have;
infile datalines dsd truncover;
input member (start1 end1 start2 end2) (:date11.) /*days2019 days2020 days2021 days2022 days2023*/ ;
format start1 end1 start2 end2 date11.;
datalines;
123,1-Mar-20,1-Apr-20,1-Feb-22,30-Jun-23,0,31,0,333,180
456,1-Jan-19,1-Jan-20,,,365,1,0,0,0
789,13-Apr-23,15-Apr-23,,,0,0,0,0,3
;
data want;
set have;
array dates{2,2} start1 end1 start2 end2;
format start_dt end_dt from_dt to_dt date11.;
do k=1 to dim1(dates);
if nmiss(dates[k,1],dates[k,2]) then continue;
start_dt =dates[k,1];
end_dt =dates[k,2];
from_dt=start_dt;
do i=0 by 1;
to_dt=min(intnx('year',start_dt,i+1,'b'),end_dt);
year=year(from_dt);
days=to_dt-from_dt;
output;
if to_dt=end_dt then leave;
from_dt=intnx('year',start_dt,i+1,'b');
end;
end;
drop start1 end1 start2 end2 k i;
run;
proc print data=want;
run;
... View more
01-06-2023
05:26 PM
I think you have chosen a poor layout of the data to do this. A better layout would be
Want:
ID_1 DOB year age
A2543 08OCT1993 2018 26
A2543 08OCT1993 2019 27
A3667 12JUL2003 2018 15
A3667 12JUL2003 2019 16
@gabagotati wrote:
Thanks for you response. The reason I am interested in extracting the specific month and day is that is I have another variable (date of enrollment), and I'd like to find their age at this date.
For A2543 in my example, they are 18 after their birthday of 08OCT2018 and before their next birthday 08OCT2019. If their enrollment date was on 01JUN2019, they would be 18 on this day. Your solution would yield age_2019 of 19, which would not be what I want.
Apologies for not including this piece in my original post.
However, to address the problem you now state, I make up some data and address the solution.
data have;
input ID $ DOB :date9. date_of_enrollment :date9.;
cards;
A2543 08OCT1993 01JUN2019
A3667 12JUL2003 12JUL2020
A3624 30MAR2000 19JAN2021
;
data want;
set have;
age_at_enrollment = intck('year',dob,date_of_enrollment,'c');
run;
... View more
09-20-2022
07:35 AM
1 Like
data have;
input (ID_1 ID_2 ID_3 ID_4)($);
datalines;
A2543 A3700 C3404 A4314
A3667 C1000 F3123 A3414
A3624 D1434 F1334 A0394
A6000 A4303 A3802 A4137
B7000 B6205 B5310 B1394
;
data relevant_ID;
length salesID $3;
input salesID;
datalines;
A36
A37
A38
A39
A40
A41
A42
A43
A44
A45
A46
A47
A48
A49
A50
;
proc sql noprint;
select distinct salesID into :salesID separated by '|' from relevant_ID;
quit;
options noquotelenmax;
data want;
set have;
length all $ 4000;
all=catx('|',of ID_:);
relevant_match=0;
if prxmatch("/&salesID./",all) then relevant_match=1;
drop all;
run;
... View more
08-25-2022
07:47 AM
data have;
input subject $ year disease1 disease2 disease3;
datalines;
a 2019 1 1 1
a 2020 0 0 0
a 2021 0 0 0
a 2022 0 0 0
b 2019 0 1 1
b 2020 1 0 0
b 2021 1 0 0
b 2022 0 0 1
;
data d1;
set have(where=(disease1=1));
year=year+1;output;
year=year+1;output;
keep subject year;
run;
data d2;
set have(where=(disease2=1));
year=year+1;output;
year=year+1;output;
keep subject year;
run;
data d3;
set have(where=(disease3=1));
year=year+1;output;
year=year+1;output;
keep subject year;
run;
data want;
if _n_=1 then do;
declare hash d1(dataset:'d1');
d1.definekey('subject','year');
d1.definedone();
declare hash d2(dataset:'d2');
d2.definekey('subject','year');
d2.definedone();
declare hash d3(dataset:'d3');
d3.definekey('subject','year');
d3.definedone();
end;
set have;
if d1.check()=0 then disease1=1;
if d2.check()=0 then disease2=1;
if d3.check()=0 then disease3=1;
run;
... View more