BookmarkSubscribeRSS Feed
SASHunter
Obsidian | Level 7

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:

13 REPLIES 13
Haikuo
Onyx | Level 15

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

SASHunter
Obsidian | Level 7

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

Haikuo
Onyx | Level 15

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

SASHunter
Obsidian | Level 7

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

ChrisHemedinger
Community Manager

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

It's time to register for SAS Innovate! Join your SAS user peers in Las Vegas on April 16-19 2024.
Astounding
PROC Star

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.

SASHunter
Obsidian | Level 7

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

Astounding
PROC Star

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.

ChrisHemedinger
Community Manager

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

It's time to register for SAS Innovate! Join your SAS user peers in Las Vegas on April 16-19 2024.
Astounding
PROC Star

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.

SASHunter
Obsidian | Level 7

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

SASHunter
Obsidian | Level 7

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

ef_
Calcite | Level 5 ef_
Calcite | Level 5

I've run into a similar problem. I've defined a macro variable in a program in process flow A, but when the process flow step with conditional execution on the macro's value runs in process flow B, it doesn't recognize the macro. However, other programs in process flow B can output the correct value of the macro using %put.

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!

SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

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
  • 13 replies
  • 3132 views
  • 0 likes
  • 5 in conversation