Date: Mon, 14 Jul 2003 16:59:39 -0400
Reply-To: "Fehd, Ronald J. (PHPPO)" <rjf2@CDC.GOV>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: "Fehd, Ronald J. (PHPPO)" <rjf2@CDC.GOV>
Subject: Re: simple data set merge/appending ??
Content-Type: text/plain
> From: JM Doyle [mailto:doylejm@JMU.EDU]
> subject: RE: simple data set merge/appending ??
you've already figured out that this is knot a simple merge.
the SQL whizards may have something to make this work.
otherwise you'll have to prepare a third data set PADDING
which has the XVAR=. that you want
*combine YEAR2001 and YEAR2002;
proc FREQ data = BOTHYEARS;
tables ID
\ noprint
out = ID;
tables YEAR
\ noprint
out = YEAR;
*drop Count and Percent from both;
*snipped from my macro FREQXTAB;
DATA PADDING;
%DO I = 1 %TO &DIM_VARS;
do Ptr&I. = 1 to Nobs&I.;
set &&VARS&I point = Ptr&I. nobs = Nobs&I.; %*%DO I=1:&DIM_VARS;%END;
output;
%DO I = 1 %TO &DIM_VARS; %*do Ptr&I.; end; %END;
stop;
which will expand to:
DATA PADDING;
retain Xvar .;
do Ptr1 = 1 to Nobs1;
do Ptr2 = 1 to Nobs2;
set ID point = Ptr1 nobs = Nobs1;
set YEAR point = Ptr2 nobs = Nobs2;
output;
end;
end;
stop;
DATA WANTED;
set PADDING
YEAR2001
YEAR2002;
by Id Year;
Ron Fehd the macro maven CDC Atlanta GA USA RJF2@cdc.gov
--> cheerful provider of UNTESTED SAS code from the Clue?Gee!Wrx <--
By using your intelligence
you can sometimes make your problems twice as complicated.
-- Ashleigh Brilliant
> I want to append/merge two data sets that look like this:
>
> First data set is:
>
> ID YEAR XVAR
> 1 2001 10
> 2 2001 16
>
> Second data set is:
>
> ID YEAR XVAR
> 1 2002 11
> 2 2002 17
> 3 2002 19
>
> I want the combined data to allow for a missing obs. for ID=3
> in 2001 like this:
>
> ID YEAR XVAR
> 1 2001 10
> 1 2002 11
> 2 2001 16
> 2 2002 17
> 3 2001 .
> 3 2002 19
>
> With a merge or a set command, I don't get the missing
> observation in 2001 for ID=3.