Sampling

Accepted Solution Solved
Reply
Frequent Contributor
Posts: 121
Accepted Solution

Sampling

I have the following code applied to the ttached dataset. I am trying to make it so that I end up with a dataset where 80% of the total loan count contained in LoanPopulation are purchased loans. So far I have the following code and I am having trouble passing the n from the proc means into the n of the proc surveyselect.

Any takers?

Thanks in advance.

proc means data=LoanPopulation n;

var Loan_ID;

output=want;

run;

proc surveyselect data=loan_population3

   method=srs n=(.8*n) out=PUR_sample;

   where purpcd='PUR';

run;

Attachment

Accepted Solutions
Solution
‎07-16-2014 09:15 AM
Super User
Posts: 9,682

Re: Sampling

 

%let dsid=%sysfunc(open(LoanPopulation));
%let n=%sysfunc(attrn(&dsid,nlobs));
%let dsid=%sysfunc(close(&dsid ));

proc surveyselect data=loan_population3
   method=srs n=(.8*&N) out=PUR_sample;
   where purpcd='PUR';
run;

Xia Keshan

View solution in original post


All Replies
Super Contributor
Posts: 644

Re: Sampling

You need to create a macro variable with the value n

Proc SQL noprint ;

     select n into :N from LoanPopulation ;

Quit ;

proc surveyselect data=loan_population3

   method=srs n=(.8*&N) out=PUR_sample;

   where purpcd='PUR';

run;

Richard

Solution
‎07-16-2014 09:15 AM
Super User
Posts: 9,682

Re: Sampling

 

%let dsid=%sysfunc(open(LoanPopulation));
%let n=%sysfunc(attrn(&dsid,nlobs));
%let dsid=%sysfunc(close(&dsid ));

proc surveyselect data=loan_population3
   method=srs n=(.8*&N) out=PUR_sample;
   where purpcd='PUR';
run;

Xia Keshan

Frequent Contributor
Posts: 121

Re: Sampling

Ksharp,

Thanks. While I get N to correctly resolve to my loan count, once I reach n=(.8*&N) in my proc select, SAS doesn't recognize the '*' symbol and generates an error, without performing the multiplication.

ANy ideas on how to work around this?

Christos

Respected Advisor
Posts: 3,777

Re: Sampling

%sysevaF(.8*&N,INTEGER)

Respected Advisor
Posts: 3,777

Re: Sampling

Why not just use RATE=.8

proc surveyselect data=sashelp.class out=sample1 seed=123 method=srs  rate=.8;
  
run;
proc print;
  
run;
proc surveyselect data=sashelp.class method=srs n=%sysevalF(.8*19,ceil) out=sample2 seed=123;
  
run;
proc print;
  
run;
proc compare base=sample1 compare=sample2;
   run;
Super User
Posts: 9,682

Re: Sampling

As Mr. NULL did:

proc surveyselect data=loan_population3

   method=srs n=%sysevalF(0.8*&N,INTEGER)    out=PUR_sample;

   where purpcd='PUR';

run;

Frequent Contributor
Posts: 121

Re: Sampling

Thanks. My SAS also doesn't like the close function; the file remains open and I get an ERROR. This is turning out to be an issue, b/c once the file has been opened, I can't use it for anything else unless it's closed.

The ERROR reads "Argument 1 to function CLOSE referenced by the %sysfunc or %qsysfunc macro function is not a number."

Thanks for the help so far; this should be one of my last questions on this task.

Super User
Posts: 9,682

Re: Sampling

Sorry. should be :

%let dsid=%sysfunc(open(  LoanPopulation));

%let n=%sysfunc(attrn(&dsid,nlobs));

%let dsid=%sysfunc(close( &dsid ));

☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 8 replies
  • 322 views
  • 7 likes
  • 4 in conversation