Hi All,
I Need help
This is my code
Data exam;
input x1 x2 x3 x4 x5 x6;
cards;
0 0 0 0 0 0
0 0 0 0 0 0
0 1 2 4 6 7
0 0 2 1 4 1
data exam1;
set exam;
array xall{6} x1 x2 x3 x4 x5 x6;
array temp[6] (0 0 0 0 0 0);
Do i = 1 to dim(xall);
IF i = 1 and xall{i}=. then temp{i} = 9999 ;
else if i=1 and xall{i}= 0 then temp{i} = 8888 ;
else if i=1 and xall{i} >0 then temp{i} = xall[i] ;
IF i >1 and (temp{i-1}=. and xall{i}=.) then temp{i} = 9999 ;
else if i >1 and (temp{i-1}=0 and xall{i}=0) then temp{i} = 8888 ;
else if i >1 and (temp{i-1}>0 and xall{i}>0) then temp{i} = min(temp{i-1},xall{i});
end;
run;
0 0 0 0 0 0 8888 8888 8888 8888 8888 8888
0 0 0 0 0 0 8888 8888 8888 8888 8888 8888
0 1 2 4 6 7 8888 1 1 1 1 1
0 0 2 1 4 1 8888 8888 1 1 1 1
Data exam;
input x1 x2 x3 x4 x5 x6;
cards;
0 0 0 0 0 0
0 0 0 0 0 0
0 1 2 4 6 7
0 0 2 1 4 1
;
data want;
set exam;
array t x1-x6;
array j(6);
do over t;
if t then j(_i_)=t;
end;
if n(of j(*)) then min=min(of j(*));
else min=0;
drop j:;
run;
Data exam;
input x1 x2 x3 x4 x5 x6;
cards;
0 0 0 0 0 0
0 0 0 0 0 0
0 1 2 4 6 7
0 0 2 1 4 1
;
data want;
set exam;
array t x1-x6;
do over t;
if t then min=min(t,min);
end;
if min=. then min=0;
run;
Data exam;
input x1 x2 x3 x4 x5 x6;
cards;
0 0 0 0 0 0
0 0 0 0 0 0
0 1 2 4 6 7
0 0 2 1 4 1
;
run;
data exam1;
set exam;
array xall{6} x1 x2 x3 x4 x5 x6;
array temp[6] $;
min=8888;
*calculate min;
Do i=1 to dim(xall);
if xall(i) > 0 then do;
if min>xall{i} then min=min(min,xall(i));
end;
end;
*feed minimum value to every variable;
Do i=1 to dim(temp);
temp(i)=ifn(min(min,xall(i))=0,8888,min(min,xall(i)));
end;
drop i;
run;
Does your data have any negative values?
It is not clear what you expect as result or why you are using the temp array, the constant 8888, please clarify.
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!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.