Hi,
I've been struggling with a do loop in SAS and would be grateful for any assistance. This is the data I have:
data have;
input Parameter $ COL1 $ COL2 $;
cards;
Intercept AGE DRINKPATTERN
DRINKPATTERN AGE DRINKPATTERN
DRINKPATTERN AGE DRINKPATTERN
DRINKPATTERN AGE DRINKPATTERN
DRINKPATTERN AGE DRINKPATTERN
FISHLASTWEEK AGE DRINKPATTERN
AGE AGE DRINKPATTERN AGE DRINKPATTERN
AGE AGE DRINKPATTERN AGE DRINKPATTERN
AGE AGE DRINKPATTERN AGE DRINKPATTERN
FISHLASTWEEK*AGE AGE DRINKPATTERN
FISHLASTWEEK*AGE AGE DRINKPATTERN
FISHLASTWEEK*AGE AGE DRINKPATTERN
;
run;
I want to assess whether the string values contained in the variables COL1 or COL2 are evident in the field Parameter and if so assign a value of 2 to the variable TYPE.
The macro I created is below. The problem I am having is that the if statement does not seem to generate and the mprint option highlights this. Any assistance
is greatly appreaciated,
thanks,
%macro ClassIdentifier(value);
data want;
set have;
TYPE = 1;
%do i=1 %to &Value;
%let Varname = COL&i;
%if %index(Parameter, &Varname ) NE 0 %then TYPE = 2;
run;
%end;
%mend;
options mprint;
%ClassIdentifier(2)
I've been struggling with a do loop in SAS and would be grateful for any assistance. This is the data I have:
data have;
input Parameter $ COL1 $ COL2 $;
cards;
Intercept AGE DRINKPATTERN
DRINKPATTERN AGE DRINKPATTERN
DRINKPATTERN AGE DRINKPATTERN
DRINKPATTERN AGE DRINKPATTERN
DRINKPATTERN AGE DRINKPATTERN
FISHLASTWEEK AGE DRINKPATTERN
AGE AGE DRINKPATTERN AGE DRINKPATTERN
AGE AGE DRINKPATTERN AGE DRINKPATTERN
AGE AGE DRINKPATTERN AGE DRINKPATTERN
FISHLASTWEEK*AGE AGE DRINKPATTERN
FISHLASTWEEK*AGE AGE DRINKPATTERN
FISHLASTWEEK*AGE AGE DRINKPATTERN
;
run;
I want to assess whether the string values contained in the variables COL1 or COL2 are evident in the field Parameter and if so assign a value of 2 to the variable TYPE.
The macro I created is below. The problem I am having is that the if statement does not seem to generate and the mprint option highlights this. Any assistance
is greatly appreaciated,
thanks,
%macro ClassIdentifier(value);
data want;
set have;
TYPE = 1;
%do i=1 %to &Value;
%let Varname = COL&i;
%if %index(Parameter, &Varname ) NE 0 %then TYPE = 2;
run;
%end;
%mend;
options mprint;
%ClassIdentifier(2)