BookmarkSubscribeRSS Feed
Hodoree
Calcite | Level 5


%macro case_when (case_1,case_2);
case
when t2.BGT_CNT > 1 then &case_1.
else &case_2.
end
%mend case_when;

 

proc sql ;
create table Work.FORE_BGT_&period_file. as
select distinct
  t1.PJT_NO
  , t1.GUBUN1
  , t1.GUBUN2
  , t1.GUBUN3
  , t1.GUBUN4
  , t1.GUBUN5
  , t1.Task_Name1
  , %case_when(sum(t1.B_Qty)
       , t1.B_Qty)             as B_Qty  format comma32.
  , %case_when("KRW"
     ,t1.B_Curr)             as B_Curr
  , %case_when(1
     ,t1.B_Rate)             as B_Rate  format comma32.2
  , %case_when(sum(B_BGT_Amt) / sum(t1.B_Qty)
     ,t1.B_Unit)             as B_Unit  format comma32.1
  , %case_when(sum(B_BGT_Amt
     ,t1.B_BGT_Amt)            as B_BGT_Amt format comma32.
  , %case_when(sum(sum(B_AOP_Amt)
     ,t1.B_AOP_Amt)            as B_AOP_Amt format comma32.


From Work.FORE_BGT_RAW_&period_file.           as t1

Left Join Work.FORE_BGT_Curr_CNT_&period_file.          as t2
on t1.PJT_NO = t2.PJT_NO
and t1.GUBUN1 = t2.GUBUN1
and t1.GUBUN2 = t2.GUBUN2
and t1.GUBUN3 = t2.GUBUN3
and t1.GUBUN4 = t2.GUBUN4
and t1.GUBUN5 = t2.GUBUN5
and t1.Task_Name1 = t2.Task_Name1

group by

   t1.PJT_NO
  , t1.GUBUN1
  , t1.GUBUN2
  , t1.GUBUN3
  , t1.GUBUN4
  , t1.GUBUN5
  , t1.Task_Name1

order by

   t1.PJT_NO
  , t1.GUBUN1
  , t1.Task_Name1
  , t1.GUBUN2
  , t1.GUBUN3
  , t1.GUBUN4
  , t1.GUBUN5

;
quit;

2 REPLIES 2
ballardw
Super User

Please clarify what you mean by "cannot implement again".

 

A common first step in debugging anything involving macros is to set OPTIONS MPRINT; prior to running the code involving the macro(s). The log should contain more detailed output of the code generated by the macros.

 

An unfortunate fact of life when coding macros is that you can create code that will render a SAS session unstable with a variety of logic errors. Common ones involve unclosed or unbalanced quotes and parentheses.

Without data we can't tell exactly what went wrong. If you are getting errors then post the log. If the SAS session appears not to be responding then you have one of the aforementioned code issues and you will likely have to shut down the SAS session and restart. SAVE code first if possible.

 

I would suggest that instead of blindly running a macro such as you have shown that you create a small data set and test each separate call in one call to Proc SQL. That may tell you which specific call(s) are causing problems.

 

I suspect at least one of the issues is with this bit:

, %case_when(sum(B_BGT_Amt
     ,t1.B_BGT_Amt)            as B_BGT_Amt format comma32.

there are two ( but only one )  => unbalanced parentheses.

If you attempted to run this code more than once then you have likely stacked up multiple sets of unbalanced parentheses and can't recover.

 

Hodoree
Calcite | Level 5

Thank you Sir !!

I solved this problem for your advise.

parenthesis is incorrect

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 468 views
  • 1 like
  • 2 in conversation