Date: Fri, 20 Jul 2007 13:33:00 -0500
Reply-To: Sien Chieh Tay <louis.psych@GMAIL.COM>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: Sien Chieh Tay <louis.psych@GMAIL.COM>
Subject: Re: Invalid programming statement
In-Reply-To: <1184934788.887131.81820@g4g2000hsf.googlegroups.com>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Hey! Thanks so much for your help! You guys are brilliant.
****************
create table d1 as
select *, INT(RANUNI(0)*&MAXNUM) + 1 as x
from KDI10
where TID=&A & kid=calculated x;
%END;
%MEND X;
****************
John, I've tried out the macro you sent using the table d&a, but one problem
encountered is that the x value is generated for each observation in the
table. As a result, I obtain different KIDs for each TID. Instead, I hope to
get from
> TID KID
> 1 1
> 1 1
> 1 2
> 1 2
> 2 1
> 2 1
> 2 1
> 2 2
> 2 2
> 2 2
> 2 3
> 2 3
> 2 3
to say
> TID KID
> 1 1
> 1 1
> 2 3
> 2 3
> 2 3
Thus, in each TID, i want to randomly select a whole set of KIDs.
Toby, I looked at PROC surveyselect, but it does not seem to do what I want.
Unless there is something which I can specify to do this?
Thanks also for pointing out the mistake Gerhard!
Really appreciate all your help.
Louis
On 7/20/07, ckxplus@yahoo.com <ckxplus@yahoo.com> wrote:
>
> Hello Louis,
>
> There are at least two problems with your macro. First is that you're
> using an assignment statement "X = INT(RANUNI(0)*MAXNUM) + 1;" within
> proc sql. The second problem is that you're referring to MAXNUM as a
> variable when in fact it's a macro variable.
>
> Here's what your macro would look like using just proc sql. Hope this
> will help you to the next step. You'll probably want to remove the
> proc sql statement from the macro and run the macro within proc sql.
> Maybe table d&a is closer to what you want than just d1.
>
> Good luck,
> John Hendrickx
>
> %MACRO X; ** START OF X MACRO;
> %DO A=1 %TO 10; *** Creating Loop for TEAMS 1-10;
>
>
> PROC SQL NOPRINT; ***Obtain maximum KID within TID;
> SELECT MAX(KID) INTO :MAXNUM
> FROM KDI10
> where TID=&A;
>
> create table d1 as
> select *, INT(RANUNI(0)*&MAXNUM) + 1 as x
> from KDI10
> where TID=&A & kid=calculated x;
> %END;
> %MEND X;
>
>
> On 20 jul, 09:30, louis.ps...@GMAIL.COM (Louis) wrote:
> > Hi, I am trying to obtain a data set D1 from KDI10. Below is a sample of
> the
> > data: "KDI10"
> >
> > TID KID
> > 1 1
> > 1 1
> > 1 2
> > 1 2
> > 2 1
> > 2 1
> > 2 1
> > 2 2
> > 2 2
> > 2 2
> > 2 3
> > 2 3
> > 2 3
> >
> > The data set D1 is based on a random selection of KID within each TID.
> > However, the problem I face is that 'X = INT(RANUNI(0)*MAXNUM) + 1;' is
> not
> > valid. I am unsure how to resolve this problem. See a part of the syntax
> below.
> >
> > Would really appreciate your help! Thanks!
> >
> > Louis
> >
> > ****************************
> >
> > %MACRO X; ** START OF X MACRO;
> > %DO A=1 %TO 10; *** Creating Loop for TEAMS 1-10;
> >
> > DATA D1; SET KDI10;
> > IF TID=&A;
> >
> > PROC SQL NOPRINT; ***Obtain maximum KID within TID;
> > SELECT MAX(KID) INTO :MAXNUM
> > FROM D1;
> > X = INT(RANUNI(0)*MAXNUM) + 1; *** PROBLEM: Statement is not valid or
> it
> > is used out of proper order;
> >
> > DATA D1; SET D1;
> > IF KID = X;
> > %END;
> > %MEND X;
>
|