BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
mduarte
Quartz | Level 8

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..

1 ACCEPTED SOLUTION

Accepted Solutions
jimbarbour
Meteorite | Level 14

@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

3 REPLIES 3
jimbarbour
Meteorite | Level 14

@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

mduarte
Quartz | Level 8

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.

 

jimbarbour
Meteorite | Level 14

Excellent.  Glad it worked.

 

Jim

 

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

Creating Custom Steps in SAS Studio

Check out this tutorial series to learn how to build your own steps in SAS Studio.

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
  • 3 replies
  • 1568 views
  • 1 like
  • 2 in conversation