Desktop productivity for business analysts and programmers

Getting a macro variable to resolve when using a Conditonal for a process

Reply
Frequent Contributor
Posts: 80

Getting a macro variable to resolve when using a Conditonal for a process

Hi,

I am basically new at SAS Enterprise Guide, so please bear with me.  I am using EG 4.3. 

I have a process that runs on my Local machine.   It prompts for three items:  The Filename, the Month (MMM), and the Year (YY).  This part works great. 

It then uses that information to find the file to read and then runs another process to do some checks on the file.  (Example,  it sorts and checks for duplicates.)

If this goes well and the last check produces an empty file - then I want to upload my file to the Remote Machine. 

What I am trying to do is create a macro variable that I can read to determine if the file can be uploaded or not.  So I added the following to the bottom of the last process:

/* Test for conditional processing */

%let dsid=%sysfunc(open(saved.sort_check));

%let nobs=%sysfunc(attrn(&dsid,nobs));

%let rc=%sysfunc(close(&dsid));

/* The value of the column EMPTY_ ROWS will be used in the conditional

   processing node to determine  which branch should be executed. */

data test_check (keep=empty_rows);

length empty_rows $2;

if &nobs = 0 then empty_rows = 'Y';

else do;

  empty_rows = 'N';

end;

run;

/* Create the macro variable that I can use to test with. */

DATA _NULL_;

    SET WORK.test_check;

    call symput('check',empty_rows);

run;

%put ✓

I right clicked on the next process (which is the upload process) and inserted the following Condition:    This is what is under 'If the condition is true:

  "&check" equal to Y

I get the following error:

1      ;*';*";*/;quit;run;
2      OPTIONS PAGENO=MIN;
3      data _NULL_; rc = 0;
4      if "&check" = Y then

WARNING: Apparent symbolic reference CHECK not resolved.

5         rc = 1;
6      CALL SYMPUT('_egrc', PUT(rc,1.));
7      stop;
8      run;

NOTE: Variable Y is uninitialized.

NOTE: DATA statement used (Total process time):

  real time       0.00 seconds
  cpu time        0.00 seconds
9    
10     QUIT; RUN;
11    

How can I use a macro variable that I created in the program, inside the Conditional process?

Thanks,

Nancy

:smileyplain:

Respected Advisor
Posts: 3,124

Re: Getting a macro variable to resolve when using a Conditonal for a process

From SAS log, I see two issues here:

1. WARNING: Apparent symbolic reference CHECK not resolved. You need to %global the "check" macro viable.

2. NOTE: Variable Y is uninitialized. It means you need  to add quote :

if "&check" = "Y" then....

Without quote, Y will be interpreted  as a variable name.

Haikuo

Frequent Contributor
Posts: 80

Re: Getting a macro variable to resolve when using a Conditonal for a process

I already have the variable CHECK in the global statement at the top of the program.  It resolves in the log when I do %put &check to 'Y'.

I went back into the Conditional Processor (for the Upload process) and changed to have double quotes around the &check and the Y.

This is what I get now when i look inside the Conditonal Logic Log:

1                                                      The SAS System                             09:57 Monday, May 20, 2013

1      ;*';*";*/;quit;run;
2      OPTIONS PAGENO=MIN;
3      data _NULL_; rc = 0;
4      if "&check" = "Y" then

WARNING: Apparent symbolic reference CHECK not resolved.

5         rc = 1;
6      CALL SYMPUT('_egrc', PUT(rc,1.));
7      stop;
8      run;

NOTE: DATA statement used (Total process time):

  real time       0.00 seconds
  cpu time        0.00 seconds

9    
10     QUIT; RUN;
11   

Thanks for your reply.

Nancy

Respected Advisor
Posts: 3,124

Re: Getting a macro variable to resolve when using a Conditonal for a process

This is odd. OK, check your global macro variable inventory right before you use it, to see if CHECK is there:

%put _global_;

data _NULL_; rc = 0;

blah..

Haikuo

update: on a side note, of course I don't have your whole picture, so if my comments are off, just ignore it. So from your posted code, it seems to me you don't need so many hoops in between, all you need is to evaluate "NOBS". Say instead of

if "&check" = "Y" then

why not use:

if "&nobs"=0 then  ? In my eyes, You can even use NOBS further down to road to eliminate "RC".

just my 2 cents

Frequent Contributor
Posts: 80

Re: Getting a macro variable to resolve when using a Conditonal for a process

That is probably true about just using &nobs instead of &check.  But, for now I want to get it to at least work!

So I want to give you a better picture of what I am trying to do.   If the file at the end of 'Read in csv...' is empty, then I want to continue with the Upload.   Upload was created using the Upload to Server - Wizard.  This is where I put the conditional processing behind.  Like I said, I am really just learning EG.  So anyway, I created that macro variable '&check' to be able to do the conditional process before Upload is executed.  I hope this helps in describing what I am trying to do.  Thanks

EG.PNG

Community Manager
Posts: 2,691

Re: Getting a macro variable to resolve when using a Conditonal for a process

Another possible approach might be to use a variation of this technique:

Export and download any file from SAS Enterprise Guide - The SAS Dummy

This would probably require a bit of re-arranging in your flow, but it might end up with fewer steps.

Chris

Respected Advisor
Posts: 4,955

Re: Getting a macro variable to resolve when using a Conditonal for a process

That's a lot of hoops to jump through, for the result you are looking for.  If you only need &_ERGC, why not something simple?

data _null_;

   call symput('_ergc', put(done, 1.);

   stop;

   set saved.sort_check end=done;

run;

You'll have to examine to see whether &_ERGC takes on the right values or whether it needs to be switched around.

Good luck.

Frequent Contributor
Posts: 80

Re: Getting a macro variable to resolve when using a Conditonal for a process

Hi Chris and Astounding,

I am using the Projects Conditional menu to create this condition.  I really would like to figure this out and be able to explain why it doesn't resolve.

When I gave the log - it's the log from the Conditional Logic Log.  It is not something I hard coded.

Is there any other way to figure this out, without recoding my process?

Thanks,

Nancy

Respected Advisor
Posts: 4,955

Re: Getting a macro variable to resolve when using a Conditonal for a process

Nancy,

First, let me simplify my code slightly:

data _null_;

  call symputx('_ergc', done);

  stop;

  set saved.sort_check end=done;

run;

Then I have to ask ... if you can add code to the end of your process, why couldn't you replace that code with this DATA step?  It creates &_ERGC with a value of 1 when there are 0 observations in saved.sort_check, and a value of 0 when there are observations in saved.sort_check.  Wouldn't that be sufficient?

Good luck.

Community Manager
Posts: 2,691

Re: Getting a macro variable to resolve when using a Conditonal for a process

I believe the DATA step that references _EGRC in Nancy's example is generated by the Condition feature on the task that is running.  You won't be able to modify the code in that step, so you'll have to craft your macro variable to fit within it.

That said, it's not obvious to me why it's not working as Nancy intends...

Chris

Respected Advisor
Posts: 4,955

Re: Getting a macro variable to resolve when using a Conditonal for a process

OK, some of the results are clearly puzzling.  Why should &CHECK not be found?  But the first correction often fixes the later issues.  So I would start with the condition entered.  If it was entered as:

"&check" equal to Y

It should probably be entered as:

"&check" equal to "Y"

I'm not a big EG user, so I'm a bit out of my element.  But that looks like the first correction to make.

Frequent Contributor
Posts: 80

Re: Getting a macro variable to resolve when using a Conditonal for a process

Hi Astounding,

Like I said I am new to EG.   I am trying to use what I have seen that should work.  So when I saw that the  Conditional Processing of Prompts and Macro variables should be able to do what I wanted, I tried to incorporate that into my process.  Look at my process flow below.  If the process  'Program' produces the macro variable &check > 0 then I don't want to do the 'Upload Data...'  process or anything after that.  The upload is what has the Conditional process behind it.  Maybe I am doing something wrong and have put the Conditional Process check at the wrong place.  

How could I incorporate your code into my system (not using the Conditional Process) and stop the process if &check (or &nobs) = 0?

Thanks, Nancy

EG_Project_Flow.PNG

Frequent Contributor
Posts: 80

Re: Getting a macro variable to resolve when using a Conditonal for a process

Chris (or anyone else),

 

I have read many articles that you have written about EG, so I know you would be the one to ask this question.

When I have the macro variable that I have created in the prior process (and made into a global variable), how do I write it in the Conditonal Processing dialog box?  With quotes around it or without quotes around it.   See image below.

Regards,

Nancy Conditional.PNG

Message was edited by: Nancy Hunter

Ask a Question
Discussion stats
  • 12 replies
  • 977 views
  • 0 likes
  • 4 in conversation