BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
Xiaoyi
Obsidian | Level 7

I created a macro code that calculate 95%CI. When I run the MACRO code (with real data and var names), it doesn't execute, nothing happens, the log just copies the code. I tested the code with actual var names before creating the macro. It run well and generated results but when i substitute with macro var, nothing happens. I could not find anything missing or wrong. I checked the community and saw similar questions, but not definite answers. I wonder if anyone has the same issue and there is a solution. Thanks. 

This code runs well before MACRO, but the MACRO Below do not work. 

data prev; set prev;

if prev_20=0 then CI_L_20=0;

if prev_20 ne 0 then CI_L_20=round((1-betainv(.975, (Den_20-_20+1), _20)), .00001)*10000;

CI_H_20=round((1-betainv(.025, (Den_20- _20), _20+1)), .00001)*10000;

run;  /*all good here till the following*/

/****** Problem starts right here, HELP!!*****/

%MACRO CI95 (PREV_FAC, CI_L_FAC, DEN_FAC, FAC, CI_H_FAC);

DATA PREV; SET PREV;

IF &PREV_FAC=0 THEN &CI_L_FAC=0;

IF &PREV_FAC NE 0 THEN &CI_L_FAC=ROUND(1-BETAINV(.975,(&DEN_FAC-&FAC+1), &FACT), .00001)*10000;

&CI_H_FAC=ROUND=ROUND(1-BETAINV(.025, (&DEN_FAC-&FAC), &FAC+1), .00001)*10000;

RUN;

%MEND CI95;

%macro CI95(Prev_20, CI_L_20, Den_20, _20, CI_H_20); /*nothing produced. In my actual codes, no comments inserted whatsoever*/

 

1 ACCEPTED SOLUTION

Accepted Solutions
Astounding
PROC Star

This line at the end would definitely cause the results you are observing:

%macro CI95(Prev_20, CI_L_20, Den_20, _20, CI_H_20);

That's not the way to call your macro.  Instead, use:

%CI95(Prev_20, CI_L_20, Den_20, _20, CI_H_20);

You might need to do this in a new program (or in a new SAS session).  The code you posted defines the macro, then starts to define it again but never completes the definition.  As shown above, calling an already-defined macro looks a little bit different.

 

Since the macro never ran, we don't know whether it  contains any errors that will show up once you run it.

View solution in original post

4 REPLIES 4
PaigeMiller
Diamond | Level 26

Please show us the entire log. Since this is a macro issue, please turn on the macro debugging options by running this line of code, the running the rest of your code.

 

options mprint symbolgen;

Copy the log as text and paste it into the window that appears when you click on the </> icon

PaigeMiller_0-1699900743276.png

--
Paige Miller
ballardw
Super User

Doesn't work is awful vague.

Are there errors in the log?: Post the code and log in a code box opened with the "</>" to maintain formatting of error messages.

No output? Post any log in a code box.

Unexpected output? Provide input data in the form of data step code pasted into a code box, the actual results and the expected results. Instructions here: https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-dat... will show how to turn an existing SAS data set into data step code that can be pasted into a forum code box using the "</>" icon or attached as text to show exactly what you have and that we can test code against.

 

You want to post the code from the log so we can verify what was actually submitted. Entirely too many examples of retyped code in questions here end up with typos that won't run or will not generate the stated problem.

YOUR macro code has a very problematic statement:

&CI_H_FAC=ROUND=ROUND(1-BETAINV(.025, (&DEN_FAC-&FAC), &FAC+1), .00001)*10000;

See the second = sign in that code? That means the variable with the name &ci_h_fac receives the comparison of the variable ROUND (the one before the 😃 with the value calculated afterward.

I strongly suspect  that your, if this is actually your code, contains a note about "Variable Round in uninitialized". Which means that the value used in this comparison was missing. Since Missing is very unlikely to equal the result of the rest of that expression then the variable received a value of 0 for "not true".

 

Since you are using the BETAINV function if &DEN_FAC-&FAC is ever less or equal to negative 1 then the value of &DEN_FAC-&FAC+1 is not valid for the shape parameter of the function.

 

 

Additionally, with macros to debug them the option MPRINT should be set before executing the macro so the code generated by the macro, and any messages appear in closer relation to the statements causing them, in detail.

 

Additionally, we have no data. So we can't really tell if your problem is related to your data.

 

BTW, in general use of the code:

data somedatasetname;
   set somedatesetname;
<other code>
;

means that the source data set is completely replaced by the output data set. Any small logic error (NOT syntax which wouldn't run) can seriously compromise the values in your data set. Second, placing that structure in a macro is doubly problematic as you could do such multiple times.

Astounding
PROC Star

This line at the end would definitely cause the results you are observing:

%macro CI95(Prev_20, CI_L_20, Den_20, _20, CI_H_20);

That's not the way to call your macro.  Instead, use:

%CI95(Prev_20, CI_L_20, Den_20, _20, CI_H_20);

You might need to do this in a new program (or in a new SAS session).  The code you posted defines the macro, then starts to define it again but never completes the definition.  As shown above, calling an already-defined macro looks a little bit different.

 

Since the macro never ran, we don't know whether it  contains any errors that will show up once you run it.

Xiaoyi
Obsidian | Level 7

OMG! You definitely saved my life! Thank you! I run the corrected one as you suggested. It turned out perfectly!!

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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
  • 329 views
  • 3 likes
  • 4 in conversation