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..
@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, 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
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.
Excellent. Glad it worked.
Jim
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.