Hello,
Here is my program. As you can see I do a random sample with replacement. I need the sample to be of the same size as the original data. Here I know that the size is equal to 81, so I fixed it. But I want that my program count the number of obsevations automatically. I find that I can use the nbos but I do not know how?
%let numsamp=1000;
%let numobs=81;
data temp04;
do bootsamp=1 to &numsamp;
do bootsamp_obsid=1 to &numobs;
random_seq_obsid=ceil(&numobs*ranuni(1));
output;
end;
end;
run;
Hi:
I think you need to refresh yourself on some Macro basic concepts: https://support.sas.com/resources/papers/proceedings13/120-2013.pdf &numobs is a macro variable and in your code, think of &numobs as a placeholder. Every time the macro processor sees &numobs, it will type 81 into your program (the current value of the macro variable). In the simplest form, the SAS macro processor is nothing more than a big "search and replace" typewriter. The & references that you see in your program are "resolved" at program compile time. By the time your program goes for execution with data, there are no & references or &macvar references in your program. When I use the term "&macvar", I am using a fake name to illustrate a macro variable being used as a placeholder in code. In your code, you have 2 macro variables: &numobs and &numsamp.
The %LET statement is only 1 way of assigning a value to the macro variable &numobs, the SQL step by PGStats is another method. There are a few more. In order to code the %LET statement method, you must know ahead of time the number of observations you want to have used in the program, every time &numobs is found. With PGStats method, you only need to know the name of the dataset whose number of obs you need. Essentially to use PGStats method, you would get rid of the %LET statement for &numobs and replace it with the whole PROC SQL step.
The SAS Macro Facility is very cool and the general rule of thumb is that you start out with a working SAS program before you start to introduce macro variables into the code. But even cooler than macro variables is the ability to have macro programs that can conditionally generate code for you. Take a look at the paper. There are a lot of other good documents on using the SAS Macro facility and once you understand how it works, it will change the way you write SAS programs.
cynthia
You can save yourself a lot of work with proc surveyselect:
proc surveyselect data=myData out=want method=urs reps=1000 samprate=100 outhits ;
run;
PG
Thanks
Yes I know that. I tried it with proc surveyselect and it works with method=urs.
I Wants to do it this way to check something.
data base_orig;
set man.nv_bd_fonds_individuels10i;
orig_seq_obsid + 1;
by crsp_fundno;
if first.crsp_fundno then orig_seq_obsid = 1;
run;
* Generate 1000 bootstrap samples of random patient IDs;
%let numsamp=1000;
%let numobs=81;
data temp04;
do bootsamp=1 to &numsamp;
do bootsamp_obsid=1 to &numobs;
random_seq_obsid=ceil(&numobs*ranuni(1));
output;
end;
end;
run;
You want the total number of observations in your dataset into a macro variable?
proc sql noprint;
select count(*) into :numobs from man.nv_bd_fonds_individuels10i;
quit;
PG
Can you please tell me how can I include this in my bootstrap. In place of having numobs=81 (constant), I will make my program count the number of observations for each id and generate 1000 bootstrap samples for each id.
In the example, I suppose that I have id=1 and I find 81 observations. So, by doing the bootstrap I will have totaly 81000 because I need the sample to be of the same size as the original data.
Hi:
I think you need to refresh yourself on some Macro basic concepts: https://support.sas.com/resources/papers/proceedings13/120-2013.pdf &numobs is a macro variable and in your code, think of &numobs as a placeholder. Every time the macro processor sees &numobs, it will type 81 into your program (the current value of the macro variable). In the simplest form, the SAS macro processor is nothing more than a big "search and replace" typewriter. The & references that you see in your program are "resolved" at program compile time. By the time your program goes for execution with data, there are no & references or &macvar references in your program. When I use the term "&macvar", I am using a fake name to illustrate a macro variable being used as a placeholder in code. In your code, you have 2 macro variables: &numobs and &numsamp.
The %LET statement is only 1 way of assigning a value to the macro variable &numobs, the SQL step by PGStats is another method. There are a few more. In order to code the %LET statement method, you must know ahead of time the number of observations you want to have used in the program, every time &numobs is found. With PGStats method, you only need to know the name of the dataset whose number of obs you need. Essentially to use PGStats method, you would get rid of the %LET statement for &numobs and replace it with the whole PROC SQL step.
The SAS Macro Facility is very cool and the general rule of thumb is that you start out with a working SAS program before you start to introduce macro variables into the code. But even cooler than macro variables is the ability to have macro programs that can conditionally generate code for you. Take a look at the paper. There are a lot of other good documents on using the SAS Macro facility and once you understand how it works, it will change the way you write SAS programs.
cynthia
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 the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.