turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

Find a Community

- Home
- /
- SAS Programming
- /
- General Programming
- /
- Sampling

Topic Options

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

07-16-2014 01:33 AM

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;

Accepted Solutions

Solution

07-16-2014
09:15 AM

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

07-16-2014 09:15 AM

%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

All Replies

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

07-16-2014 06:47 AM

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

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

07-16-2014 09:15 AM

%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

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

07-16-2014 09:54 AM

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

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

07-16-2014 09:57 AM

%sysevaF(.8*&N,INTEGER)

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

07-16-2014 10:02 AM

Why not just use RATE=.8

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

07-16-2014 10:03 AM

As Mr. NULL did:

proc surveyselect data=loan_population3

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

where purpcd='PUR';

run;

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

07-16-2014 10:30 AM

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.

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

07-17-2014 08:01 AM

Sorry. should be :

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

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

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