mirror of
https://github.com/sasjs/core.git
synced 2026-01-03 23:50:06 +00:00
feat: v1 of the mp_makedata() macro. Will create random data from an empty table definition. Many more features to be added
This commit is contained in:
@@ -9,7 +9,10 @@
|
||||
This macro can help by taking an empty table, and populating it with data
|
||||
according to the variable types and formats.
|
||||
|
||||
The primary key is respected, as well as any NOT NULL constraints.
|
||||
TODO:
|
||||
@li Respect PKs
|
||||
@li Respect NOT NULLs
|
||||
@li Consider dates, datetimes, times, integers etc
|
||||
|
||||
Usage:
|
||||
|
||||
@@ -28,6 +31,8 @@
|
||||
@param [out] obs= (500) The number of records to create.
|
||||
|
||||
<h4> SAS Macros </h4>
|
||||
@li mf_getuniquename.sas
|
||||
@li mf_getvarlen.sas
|
||||
@li mf_nobs.sas
|
||||
@li mp_getcols.sas
|
||||
@li mp_getpk.sas
|
||||
@@ -41,5 +46,42 @@
|
||||
,obs=500
|
||||
)/*/STORE SOURCE*/;
|
||||
|
||||
%local ds1 c1 n1 i col charvars numvars;
|
||||
|
||||
%if %mf_nobs(&libds)>0 %then %do;
|
||||
%put &sysmacroname: &libds has data, it will not be recreated;
|
||||
%return;
|
||||
%end;
|
||||
|
||||
%local ds1 c1 n1;
|
||||
%let ds1=%mf_getuniquename(prefix=mp_makedata);
|
||||
%let c1=%mf_getuniquename(prefix=mp_makedatacol);
|
||||
%let n1=%mf_getuniquename(prefix=mp_makedatacol);
|
||||
data &ds1;
|
||||
if 0 then set &libds;
|
||||
do _n_=1 to &obs;
|
||||
&c1=repeat(uuidgen(),10);
|
||||
&n1=ranuni(1)*5000000;
|
||||
drop &c1 &n1;
|
||||
%let charvars=%mf_getvarlist(&libds,typefilter=C);
|
||||
%do i=1 %to %sysfunc(countw(&charvars));
|
||||
%let col=%scan(&charvars,&i);
|
||||
&col=subpad(&c1,1,%mf_getvarlen(&libds,&col));
|
||||
%end;
|
||||
|
||||
%let numvars=%mf_getvarlist(&libds,typefilter=N);
|
||||
%do i=1 %to %sysfunc(countw(&numvars));
|
||||
%let col=%scan(&numvars,&i);
|
||||
&col=&n1;
|
||||
%end;
|
||||
output;
|
||||
end;
|
||||
run;
|
||||
|
||||
proc append base=&libds data=&ds1;
|
||||
run;
|
||||
|
||||
proc sql;
|
||||
drop table &ds1;
|
||||
|
||||
%mend mp_makedata;
|
||||
Reference in New Issue
Block a user