BookmarkSubscribeRSS Feed
omega1983
Calcite | Level 5
I want the following macro to loop through a series of invoices INV06 and choose them.

%macro overall;
data lIB.Drug33 (keep= DRUG_CDE1 S_P_NAME PROVIDER SRVC_PROV_NPI PRSC_PRV FROM_DTE BIRTH STATUS RECIP TENT_PAY SERV_FEE QTY_DISP);
%let status = '1';
%let drug_cde1 = 33;
if status = &status
and drug_cde1 =&drug_cde1 then
set
%do i = 1 %to 2; /*where 1 is the first number and 7 is the last*/

p_claim.Inv06_2010_&i

%end;
;
run;

%mend;

%overall;

I am trying to limit the pull to those with a status of '1' and a drug_cde of 33. However when I run the program I get the following errors;
ERROR: Variable drug_cde1 has been defined as both character and numeric.
ERROR: File WORK.IF.DATA does not exist.
ERROR: File WORK.STATUS.DATA does not exist.
ERROR: The value 1 is not a valid SAS name.
NOTE: Line generated by the macro variable "I".
1 p_claim.Inv06_2010_2
--------------------
557
ERROR: DATA STEP Component Object failure. Aborted during the COMPILATION phase.
ERROR 22-322: Syntax error, expecting one of the following: a name, a quoted string, (, -, :,
;, END, INDSNAME, KEY, KEYS, NOBS, OPEN, POINT, _DATA_, _LAST_, _NULL_.

ERROR 200-322: The symbol is not recognized and will be ignored.

ERROR 557-185: Variable p_claim is not an object.
4 REPLIES 4
SPR
Quartz | Level 8 SPR
Quartz | Level 8
Hello Omega1983,

I emulated your code with artificial data and it works fine. It means the problem lies in data. Please submit a sample of you data.

Sincerely,
SPR
darrylovia
Quartz | Level 8
A number of problems are in your code.

1) your IF statement is before your SET therefore the IF statement is executed before the SET and will never happen. How would SAS know what the value of status and drug_cde is? from what file? Also your logic to just bring in those records where status='1' and drug_cde=33 is way off on how SAS actually processes data.

2) is drug_cde a character data in your input dataset? The error message leads me to believe that

3) since you only want to "bring in" records where status='1' and drug_cde=33 just put that in your where option in the SET statement.

4) a good programming practice is not to put a %LET inside of a DATA STEP.


See below .....


%macro overall;

%local status drug_cde1 ;


%let status = '1';
%let drug_cde1 = 33;


data lIB.Drug33 (keep= DRUG_CDE1 S_P_NAME PROVIDER SRVC_PROV_NPI PRSC_PRV FROM_DTE BIRTH STATUS RECIP TENT_PAY SERV_FEE QTY_DISP);

set %do i = 1 %to 7;
p_claim.Inv06_2010_&i (where=(status=&status and drug_cde1 =&drug_cde1 ))

%end;
;
run;

%mend;

%overall
SPR
Quartz | Level 8 SPR
Quartz | Level 8
Hello Darrylovia,

I agree with your ponts 2 - 4 but not 1. I've tested it works.

Sincerely,
SPR
darrylovia
Quartz | Level 8
SPR
My bust you are correct

For those in the forum see the below code as a demostration



data s1(drop=s2) s2(drop=s1);
set sashelp.shoes;

inS1=1;
inS2=1;
run;


%macro overall;

data one;

%let Region='Africa';

if Region=&region then
set %do i=1 %to 2;
s&i
%end;
;
run;
%mend overall;
%overall;

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 4 replies
  • 3443 views
  • 0 likes
  • 3 in conversation