I know there is a DS2 thread, but I don't know how to use it in fcmp function-package, the documentation only has a multithreaded case and there is too little explanation
/*this is fcmp function*/
PROC FCMP OUTLIB=WORK.FUNCS.MATH;
FUNCTION GAUSS_DECAY(DISTANCE,SIGMA);
WEIGHT=1*EXP(-(DISTANCE-0)**2/(2*SIGMA**2));
IF WEIGHT=1 THEN WEIGHT=0;
RETURN(WEIGHT);
ENDSUB;
RUN;
QUIT;
/*Convert fcmp function package to ds2 function package*/
PROC DS2 ;
PACKAGE FUNCTION_PACK / OVERWRITE=YES LANGUAGE='FCMP' TABLE='WORK.FUNCS';
ENDPACKAGE;
RUN;
QUIT;
/*THIS IS DS2 DATA SETP*/
PROC DS2;
THREAD T / OVERWRITE=YES;
METHOD RUN();
END;
NEDTHREAD;
RUN;
DATA SAMPLE / OVERWRITE=YES;
DCL DOUBLE X HAVING LABEL '循环次数';
DCL DOUBLE WEIGHT_MEAN HAVING LABEL 'SIGMA';
DCL DOUBLE WEIGHT_MAX HAVING LABEL 'SIGMA';
DCL DOUBLE WEIGHT_MIN HAVING LABEL 'SIGMA' ;
DCL PACKAGE FUNCTION_PACK P();
DCL THREAD T T1;
METHOD INIT();
SET FROM T1 THREADS=8;
DO X =10 TO 0 BY -0.0001;
WEIGHT_MEAN= P.GAUSS_GRAPHIC(X,1.3696199923);
WEIGHT_MAX=P.GAUSS_GRAPHIC(X,1.9840148);
WEIGHT_MIN=P.GAUSS_GRAPHIC(X,0.8215555);
OUTPUT;
END;
STOP;
END;
ENDDATA;
RUN;
QUIT;
I think you have miss understood the threads concept in SAS Proc DS2!
DS2 threads are not your typical programming language threads!
DS2 Threads are stored program that can be executed in parallel. They must contains at least one explicit method (INIT, RUN, TERM), can declare local and global variables that affect the PDV, and can instantiate and use packages.
Typically,
So to translate this into Proc DS2, check this slightly modified example from Reasons to love PROC DS2
/* Create Sample Data */
data test;
do x=1 to 1231600;
j=x*x;
output;
end;
run;
proc ds2;
/* Create a thread to manipulate the records within the data set */
/* Note: You would call Native/Custom functions here */
thread newton/overwrite=yes;
dcl double y count;
dcl bigint thisThread;
drop count;
method run();
set test;
y=(x*j*x)/(j+x);
thisThread=_threadid_;
count+1;
end;
method term();
put '**Thread' _threadid_ 'processed' count 'rows:';
end;
endthread;
run;
quit;
proc ds2;
data _null_;
dcl thread newton frac;
method run();
/* Run the processing in Parallel across 4 threads */
set from frac threads=4;
end;
enddata;
run;
quit;
For additional Proc DS2 examples try these two links
Hope this helps
Please shorten your subject line, the subject of your question is not "Good morning SAS experts, I have a programming question, How do I multi-thread this DS2 process". The subject of your question is "How do I multi-thread this DS2 process". This shorter subject line will attract the proper people knowledgeable in DS2.
I think you have miss understood the threads concept in SAS Proc DS2!
DS2 threads are not your typical programming language threads!
DS2 Threads are stored program that can be executed in parallel. They must contains at least one explicit method (INIT, RUN, TERM), can declare local and global variables that affect the PDV, and can instantiate and use packages.
Typically,
So to translate this into Proc DS2, check this slightly modified example from Reasons to love PROC DS2
/* Create Sample Data */
data test;
do x=1 to 1231600;
j=x*x;
output;
end;
run;
proc ds2;
/* Create a thread to manipulate the records within the data set */
/* Note: You would call Native/Custom functions here */
thread newton/overwrite=yes;
dcl double y count;
dcl bigint thisThread;
drop count;
method run();
set test;
y=(x*j*x)/(j+x);
thisThread=_threadid_;
count+1;
end;
method term();
put '**Thread' _threadid_ 'processed' count 'rows:';
end;
endthread;
run;
quit;
proc ds2;
data _null_;
dcl thread newton frac;
method run();
/* Run the processing in Parallel across 4 threads */
set from frac threads=4;
end;
enddata;
run;
quit;
For additional Proc DS2 examples try these two links
Hope this helps
PS. The DS2 Threads definition paragraph is quoted from Mark Jordan's (@SASJedi) "Mastering the SAS DS2 Procedure" book
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.