Desktop productivity for business analysts and programmers

Conditional format based on macro value (EG prompt value)

Accepted Solution Solved
Reply
Frequent Contributor
Posts: 75
Accepted Solution

Conditional format based on macro value (EG prompt value)

I want to format my data based on a prompt value within Enterprise Guide.

e.g. if prompt_value = "A" define lead_time_format as follows:

 

proc format;
value lead_time_format
LOW-<0 = "After Arrival"
0 = "Day of Arrival"
1 = '1 day prior to Arrival';
run;

 

but otherwise (i.e. if prompt_value NE "B") define lead_time_format as follows:

proc format;
value lead_time_format
LOW-<0 = "After Departure"
0 = "Day of Departure"
1 = '1 day prior to Departure';
run;

 

I'm not sure how to go about this and so any suggestions would be appreciated..


Accepted Solutions
Solution
‎03-10-2016 05:57 PM
Frequent Contributor
Posts: 100

Re: Conditional format based on macro value (EG prompt value)

@mduarte, I might just set it up like this:

%LET  Flight_Type	=	Arrival;

proc format;
value lead_time_format
LOW-<0 = "After &Flight_Type"
0 = "Day of &Flight_Type"
1 = "1 day prior to &Flight_Type";
run;
 
DATA _NULL_;

	Status1	=	-1;
	Status2	=	 0;
	Status3	=	 1;
	
	FORMAT	Status1 lead_time_format.;
	FORMAT	Status2 lead_time_format.;
	FORMAT	Status3 lead_time_format.;
		
	PUT  "NOTE:  -1 yields "  Status1;
	PUT  "NOTE-   0 yields "  Status2;
	PUT  "NOTE-   1 yields "  Status3;
	
RUN;

I'm using a %LET statement, but you would use a SAS EG prompt.  Notice also that I changed your last line from single quotes to double.  You need to use double quotes with macro variables.

 

Here's the log.

NOTE:  -1 yields After Arrival
         0 yields Day of Arrival
         1 yields 1 day prior to Arrival

Changing the macro variable to "Departure" yields:

NOTE:  -1 yields After Departure
         0 yields Day of Departure
         1 yields 1 day prior to Departure

 

Jim

View solution in original post


All Replies
Solution
‎03-10-2016 05:57 PM
Frequent Contributor
Posts: 100

Re: Conditional format based on macro value (EG prompt value)

@mduarte, I might just set it up like this:

%LET  Flight_Type	=	Arrival;

proc format;
value lead_time_format
LOW-<0 = "After &Flight_Type"
0 = "Day of &Flight_Type"
1 = "1 day prior to &Flight_Type";
run;
 
DATA _NULL_;

	Status1	=	-1;
	Status2	=	 0;
	Status3	=	 1;
	
	FORMAT	Status1 lead_time_format.;
	FORMAT	Status2 lead_time_format.;
	FORMAT	Status3 lead_time_format.;
		
	PUT  "NOTE:  -1 yields "  Status1;
	PUT  "NOTE-   0 yields "  Status2;
	PUT  "NOTE-   1 yields "  Status3;
	
RUN;

I'm using a %LET statement, but you would use a SAS EG prompt.  Notice also that I changed your last line from single quotes to double.  You need to use double quotes with macro variables.

 

Here's the log.

NOTE:  -1 yields After Arrival
         0 yields Day of Arrival
         1 yields 1 day prior to Arrival

Changing the macro variable to "Departure" yields:

NOTE:  -1 yields After Departure
         0 yields Day of Departure
         1 yields 1 day prior to Departure

 

Jim

Frequent Contributor
Posts: 75

Re: Conditional format based on macro value (EG prompt value)

Thanks @jimbarbour.  A further complication was that I was setting flight_type dependent on the EG prompt value and flight_type didn't have global scope.  So I had to do first:

%macro setVariableValues;
%global flight_type;
%if &category = FLIGHT WITH ARRIVALS %then 
%let flight_type= "Arrival";
%else %let flight_type= "Departure";
%mend setVariableValues;

%setVariableValues;

The other error I had was having quotation marks around FLIGHT WITH ARRIVALS, i.e. I had this value first enclosed in "" then '' and then by trial and error with no quotes, which thankfully finally worked.

 

Frequent Contributor
Posts: 100

Re: Conditional format based on macro value (EG prompt value)

Excellent.  Glad it worked.

 

Jim

 

☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 3 replies
  • 313 views
  • 1 like
  • 2 in conversation