12345
12345

Reputation: 67

How to call global macro variable

I have created two global macro variables.

date=10/6/2016

b=simple

I want to create a dataset with variable which refers above macros

below are the variables which i want based on condition.

varible1: Date- which the refers the date macro variable

variable2:condition- if b =simple then condition =y or if b is not equal to simple then condition =n

So dateset will look like below

Date         condition
10/6/2016       y

Upvotes: 0

Views: 110

Answers (1)

Robert Soszyński
Robert Soszyński

Reputation: 1188

You have two options.

Number one (using macro-variables in a data step):

data result;
    format date ddmmyy10.;
    date = input("&date", ddmmyy10.);

    if "&b" = "simple" then condition = "y";
    else condition = "n";
run;

Number two (create macro and generate SAS code based on a macro-variable value):

%macro test;
data result;
    format date ddmmyy10.;
    date = input("&date", ddmmyy10.);

    %if &b = simple %then %do;
        condition = "y";
    %end;
    %else %do; 
        condition = "n";
    %end;
run;
%mend test;

%test

Edited:

Or using PROC SQL:

%let date=12/10/2016;
%let b=simple;

proc sql;
    create table result
    (
        date num format=ddmmyy10.,
        condition char(1)
    );
quit;

%macro insert;
proc sql;
    %if &b = simple %then %do;
        %let condition = y;
    %end;
    %else %do;
        %let condition = n;
    %end;

    insert into result (date, condition) values (%sysfunc(inputn(&date, ddmmyy10.)), "&condition"); 
quit;
%mend insert;

%insert

Upvotes: 2

Related Questions