08-05-2016 06:59 AM
I have a SAS dataset which contains monthly customer information (variable examples below).
Customer Date Jan16 Feb16 Mar16 Apr16 .....................
For a SAS project I have to input the reporting date to be used to restrict the dataset (&mon. 01Jun2016 for example).
CREATE TABLE TEST AS
WHERE DATE <= "&mon."d;
I want to use this reporting date within the where clause of a step rather then inputting manually. For example for 01Jun2016 variable I want the following step using JUN2016:
CREATE TABLE WANT AS
WHERE JUN2016 = .;
How do I turn the inputted prompt character into a variable without the need for manual intervention? I hope I have explained it clearly!
08-05-2016 07:04 AM - edited 08-05-2016 07:05 AM
First of all, this example illustrates the disadvantages of a wide vs. a long dataset structure. Putting data (the dates) into structure (variable names) only makes your tasks harder.
So the best solution is transposing your dataset into long format and then use the macro variable from the prompt in a where condition.
OTOH, you can easily use a macro variable as a variable name:
%let date=01jun2016; %let mon=%substr(&date,3); proc sql; create table want as select * from have where &mon = . ; quit;