BookmarkSubscribeRSS Feed
deleted_user
Not applicable
Hi there

I am having problems using prompts in EG. I want to specify an if statement to do one of two things depending on a prompt. The prompt will be either "MPANlist" or "Portfolio".

Plesae see code below. When I change the first line from "Portfolio" to "MPANlist" sas still ruuns the second if statement (which is for the prompt value"Portfolio")

Please Help!


%let Process = "Portfolio";

%macro Choose_Process;

%if $Process = "MPANList" %then %do;
PROC SQL;
CREATE TABLE WORK.Voltage_ID AS
SELECT t1.MPANCORE2,
t1.LLF,
t2.Voltage_ID,
t1.Dist_ID2
FROM MPAN_IMPORT_DIST_ID_FORMAT AS t1, WORK.TX920_LOSSES_LOOKUP_FORMAT AS t2
WHERE (t1.LLF = t2.LLF AND t1.Dist_ID2 = t2.DIST_ID);
quit;
%end;

%else %if &Process = "Portfolio" %then %do;
PROC SQL;
CREATE TABLE WORK.Voltage_ID AS
SELECT t1.MPANCORE,
t1.Dist_ID2,
t1.LLF2,
t2.Voltage_ID as TEST
FROM WORK.CALC_DIST_ID_FORMAT AS t1, WORK.TX920_LOSSES_LOOKUP_FORMAT AS t2
WHERE (t1.LLF2 = t2.LLF AND t1.Dist_ID2 = t2.DIST_ID);
QUIT;
%end;

%mend Choose_Process;

%Choose_Process
Run;
3 REPLIES 3
TomKari
Onyx | Level 15
I think your code is just about right.

A couple of changes:

First of all, in your first %if statement change $Process to &Process

Second, macro variables are different from SAS character variables. Usually, you don't put them in quotes. I'm not sure what your prompts will be like, but it is likely that the following statements will work better:

%let Process = Portfolio;
%if &Process = MPANList %then %do;
%else %if &Process = Portfolio %then %do;

Good luck!
Tom
deleted_user
Not applicable
Thanks for your help! I cannot believe I made a mistake as simple as that in the program! Amateur mistake to make!

The program runs just fine for the prompt Portfolio, but when I replace the prompt with MPANlist the following error is thrown up:

"The open data operation failed. The following data error occurred.
[error] File Work.Voltage.ID.Data does not exist."

Any ideas?
TomKari
Onyx | Level 15
It's hard to know what this problem could be. In your post, the dataset name is Work.Voltage.ID.Data

Are there periods in it, or underscores?

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!

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
  • 3 replies
  • 690 views
  • 0 likes
  • 2 in conversation