data egg;
length SUBID $5 LABTEST $40 LABTESTCODE $8 RESULT $200 UNITS $10;
input SUBID LABTEST LABTESTCODE RESULT UNITS;
datalines;
1011 LEUKOCYTES WBC 5.6 CELLS/MCL
1012 LEUKOCYTES WBC 4.14 X10^6/UL
1013 LEUKOCYTES WBC 36.3 %
1014 LEUKOCYTES WBC 11.4 G/DL
1015 LEUKOCYTES WBC 480.0 THOUS/MCL
1016 LEUKOCYTES WBC 19.0 %
1017 LEUKOCYTES WBC 0.7 %
1018 LEUKOCYTES WBC 2.8 %
1019 LEUKOCYTES WBC 10.5 %
1020 LEUKOCYTES WBC 67.0 %
;
run;
proc fcmp outlib=work.scrambling.test; * Storing functions. Recommended to store in a permanent library for ready access for intended users. ;
function scramnum (RANSUB) $ ; * Declare a function and declare the type and number of arguments it will receive;
* Alternatively keyword 'SUBROUTINE' can be used instead of 'FUNCTION' ;
length TEMPSUB NEWSUB1 $4 COUNT RANSUB Y 8;
outargs RANSUB;
* Obtain the number of observations from the input data set ;
%let DATANAME = %sysfunc(open(egg)); * Use SAS default macros to open the source data set ;
%let NUM = %sysfunc(attrn(&dataname,nlobs)); * Obtain the Number of observations;
%let DATACLOSE = %sysfunc(close(&dataname)); * Close the source data set after reading information;
X = # *Assign number of observations to a variable;
do i=1 to #
NEWSUB1=put((RANSUB + 1), 4.);
end;
COUNT +1;
return(NEWSUB1); * Return the processed value to the data set that invoked the function call;
endsub; * end the subroutine ;
quit;
options cmplib=work.scrambling; * Allows function to be available to the
current library;
* Created data set that will receive scrambled information ;
data scrambled;
length NEWSUB $4;
NEWSUB = ' '; * initialize the variable;
set egg;
OLDSUB = SUBID *1;
NEWSUB = scramnum(OLDSUB);
put NEWSUB=;
run;
data scrambled_egg (rename=NEWSUB=SUBID);
set scrambled (drop=SUBID);
drop OLDSUB;
run;
scrambling.sas
©著作权归作者所有,转载或内容合作请联系作者
- 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
- 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
- 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...