BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
nicnad
Fluorite | Level 6

Hi,

I would like to know how to store the number of records from a table in a variable and then based on that number select a random sample that is 10% of the size of the total number of records.

Here is what I came up with so far. My source table is cq_alert.closed_alert_cust :

data _NULL_;

  if 0 then set cq_alert.closed_alert_cust nobs=n;

  call symput('nrows',trim(left(put(n,8.))));

  stop;

run;

%put nobs= int(&nrows/10); /* I'm trying to store 10% of my total number of records in variable nobs */

To illustrate this better, if my source table had 100 records, I would like to create a table with 10 random records from it.

Thank you for your help and time.

1 ACCEPTED SOLUTION

Accepted Solutions
data_null__
Jade | Level 19

Just use RATE=.1 with survelselect.

data h;
   do i = 1 to 100;
     
output;
     
end;
  
run;
proc surveyselect data=h rate=.1 out=sample;
   run;

View solution in original post

4 REPLIES 4
data_null__
Jade | Level 19

Just use RATE=.1 with survelselect.

data h;
   do i = 1 to 100;
     
output;
     
end;
  
run;
proc surveyselect data=h rate=.1 out=sample;
   run;
nicnad
Fluorite | Level 6

Thank you very much for the quick reply.

For the seconds part of my question :

Lets says I have this :

data _NULL_;

  if 0 then set cq_alert.closed_alert_cust nobs=n;

  call symput('nrows',trim(left(put(n,8.))));

  stop;

run;

%put nobs= int(&nrows/10);

How do I use the variable nobs in a normal data procedure?

data_null__
Jade | Level 19

You could create a macro variable NOBS with %LET or you could create the variable in your data step and use it in code as &nobs.

%let nobs= %sysevalF(&nrows/10,INTEGER);
nicnad
Fluorite | Level 6

Exactly what I needed.

Thank you very much for your help and time!

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

What is Bayesian Analysis?

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 4 replies
  • 702 views
  • 3 likes
  • 2 in conversation