Date: Sat, 29 Apr 2006 09:01:21 -0400
Reply-To: Arthur Tabachneck <art297@NETSCAPE.NET>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: Arthur Tabachneck <art297@NETSCAPE.NET>
Subject: Re: DATA STRING MERGE
Paul,
As David pointed out, there were imbalanced parentheses. And, as you
noted, the file you imported doesn't have regions separated by commas.
Thus, if you choose to try the method I proposed, do the following.
The first part doesn't require any changes. I.e.,
%global user_mask;
***EXAMPLE OF DISTRICT STRING ENTERED BY USER FOR FINAL REPORT***;
DATA _null_;
REGION="1,2,3";
user_regionmask=0;
do i=1 to 25;
if scan(region,i,',') eq '' then i=25;
else user_regionmask=user_regionmask +
2**(scan(region,i,',')+1);
end;
call symput ('user_mask',user_regionmask);
run;
/*
For the second part, assuming region is one field containing a number of
regions separated with blanks, then try one of the following two data
steps. The first is if you are trying to find records which match at
least on of the contractor's preferred regions. The second is if you are
trying to find records which match every one of the user supplied regions:
*/
DATA EMS;
SET EMSCONS;
regionmask=0;
do i=1 to 25;
if scan(region,i) eq '' then i=25;
else regionmask=regionmask +
2**(scan(region,i)+1);
end;
if band(regionmask,&user_mask.);
RUN;
/* or, if you require contractors to match all user regions */
DATA EMS;
SET EMSCONS;
regionmask=0;
do i=1 to 25;
if scan(region,i) eq '' then i=25;
else regionmask=regionmask +
2**(scan(region,i)+1);
end;
if band(regionmask,&user_mask.) eq &user_mask.;
RUN;
Art
--------
On Fri, 28 Apr 2006 09:17:30 -0400, Paul St Louis
<pstloui@DOT.STATE.TX.US> wrote:
>Hi Arthur,
>
>Thanks for the followup and your initial response. I'm not sure what
>happened, as I clicked reply and sent a response. I've searched by my
>signon key, but I do not see the response is listed (I must have
>clicked "to the original poster", i.e. me. It's been a frenzied week
here.)
>I tried each person's suggestion.
>
>I inserted the code you sent this last time, and modified to use PROC
>IMPORT for EMSCONS. received error message:
>
> if bor(regionmask,&user_mask.) gt 0);
> -
> 388
> 76
> -
> 200
>ERROR 388-185: Expecting an arithmetic operator.
>ERROR 76-322: Syntax error, statement will be ignored.
>ERROR 200-322: The symbol is not recognized and will be ignored.
>30 cards;
>
>I then inserted the code exactly as you sent it, not using PROC IMPORT,
but
>still received error message. Attached at the end is a copy of the code I
>used.
>
>In previous attempt to use this code, the error message was as follows:
>
>127 DATA EMS; SET EMSCONS;
>128 DO I = 1 TO 25;
>129 RGN = INPUT(SUBSTR(REGION,(I*2)-1,2.));
> -
> 22
> 76
>ERROR 22-322: Syntax error, expecting one of the following: !, !!, &, *,
>**, +, ',', -, /, <, <=, <>, =, >, ><, >=, AND, EQ, GE, GT, IN, LE, LT,
>MAX, MIN, NE, NG, NL, NOT, NOTIN, OR, ^, ^=, |, ||, ~, ~=.
>ERROR 76-322: Syntax error, statement will be ignored.
>130 IF RGN NE . THEN OUTPUT;
>131 END;
>132 RUN;
>
>I apologize for not being very clear in my request, and the lack of proper
>response. Basically, this code is written to compare region codes entered
>by a user, to region codes listed in an excel worksheet. Merge, and output
>results. The excel file include contractor names, the name of the contact
>person, region numbers without comma separators, and all the other
>variables shown, therefore, the cards statement can be removed (which I
>have tried and failed.)
>
>Sigurd Hermansen,
>I believe your code will work as well, but SAS hangs on error msg shown
>above. The long version with macro code frightens a newbie like me, so I
>choose the second version.
>
>Darrell Pauley,
>You were right about the commas, but it is possible for me to set up the
>excel file without them. I will go this route.
>
>Clinton Rickards,
>Thank you for your input as well. SAS hangs on error statement shown
above.
>I have tried all variations of moving around brackets and deleting
>brackets, but still no luck.
>
>A big thank you to all for taking the time to help me out and being
patient
>with me as I flub through this. I truly appreciate it.
>
>Here is the code to date:
>
>%global user_mask;
>***EXAMPLE OF DISTRICT STRING ENTERED BY USER FOR FINAL REPORT***;
>DATA _null_;
> REGION="1,2,3";
> user_regionmask=0;
> do i=1 to 25;
> if scan(region,i,',') eq '' then i=25;
> else user_regionmask=user_regionmask +
> 2**scan(region,i,',');
> end;
> call symput ('user_mask',user_regionmask);
>run;
>
>***SET UP FLAT FILE FOR COMPARISON***;
>DATA EMSCONS (keep=CONTRACTOR NAME REGION);
> INFORMAT CONTRACTOR $50. NAME $50. REGION $50.;
> INPUT CONTRACTOR NAME REGION $50.;
> regionmask=0;
> do i=1 to 25;
>PROC SORT; BY contractor name region;
>
>DATA IMP2; SET EMSCONS;
> regionmask=0;
> do i=1 to 25;
> if scan(region,i,',') eq '' then i=25;
> else regionmask=regionmask +
> 2**scan(region,i,',');
> end;
> if bor(regionmask,&user_mask.) gt 0);
> cards;
>1 a 2, 10, 7, 9, 25
>2 b 3, 7, 4,12,14,18,22,27
>3 c 1, 2, 3,7,8,9,10,12
>4 d 5, 6, 7,1,2,9
>5 e 6, 1, 8,9,2,5,12,13,14
>RUN;
|