FUNCTION SAMPLE

Solved
Occasional Contributor
Posts: 11

FUNCTION SAMPLE

Hello,

I have a question regarding the subject,

I simulated a binomial population (variable) and I would like to take a random sample of this population.

My population is:

PROC IML;

N=100000;

MEAN=(0.074, 0.1274);

COV=(0.000302 0.000581, 0.000581 0.00156);

CALL RANDSEED(321);

P=RANDNORMAL(N,MEAN,COV);

PRINT P;

RUN;

While trying to remove a sample using the sample function:

A=SAMPLE(P, 20, "NoReplace");

the following message appears: "ERROR: Invocation of unresolveed module SAMPLE"

how to solve this problem?

Tnk.

Accepted Solutions
Solution
‎09-11-2014 03:00 PM
SAS Super FREQ
Posts: 4,239

Re: FUNCTION SAMPLE

Here is a longer explanation of using the SAMPLE function: Sample without replacement in SAS - The DO Loop

The SAMPLE function was introduced in SAS/IML 12.1 (August 2012, SAS 9.3m2).

You can use the following statements to find your version of SAS:

%put SYSVLONG = &SYSVLONG;

If you are using an old version of SAS, you can use PROC SURVEYSELECT, as shown in the blog article.

With regards to your ultimate question (distribution of the ratio), there has been a lot of work done on this question.  You might be interested in reading Hinkley's theoretical treatment

and this more modern approach

http://www.jstor.org/stable/2987992

All Replies
Posts: 2,982

Re: FUNCTION SAMPLE

There is no module named SAMPLE. I don't see it in your code.

--
Paige Miller
Occasional Contributor
Posts: 11

Re: FUNCTION SAMPLE

Hi PaigeMiller,

My full code is

PROC IML;

N = 100000;

MEAN = (0.074, 0.1274);

COV = (0.000302 0.000581, 0.000581 0.00156);

CALL RANDSEED (321);

RANDNORMAL P = (N, MEAN, VOC);

The SAMPLE = (P, 20, "noreplace");

PRINT P;

The PRINT;

RUN;

and when I run the code the following error message appears: "ERROR: Invocation of unresolveed module SAMPLE"

I need to remove the total population (n=100 000) 20 random numbers and I'm not getting.

SAS Super FREQ
Posts: 4,239

Re: FUNCTION SAMPLE

Did you look up the SAMPLE fnuction in SAS/IML? It has cut-and-paste examples.

Your code looks like it got chopped up and rearranged.  I see several transpositions, which makes me wonder whether this is an intentionally obsfucated program?

Anyway, here is the main SAS/IML doc for functions: SAS/IML(R) 13.1 User's Guide

Look at the doc for RANDNORMAL and SAMPLE.  Pay close attention to the arguments for RANDNORMAL.

Lastly, P is an Nx2 matrix.  Do you really want 20 values from that matrix, or do you want 20 OBSERVATIONS from P?  If you want 20 observations, you need to let IDX be a random sample from 1:N and then extract x=P[IDX,];

Occasional Contributor
Posts: 11

Re: FUNCTION SAMPLE

Hi Rick,

The examples have not helped me much.

I do not know this has influence, but I'm using the "SAS Enterprise Guide."

My codes not are purposely been obsfucated. I wrote them.

P is a binomial matrix NX2 yes, and I need 20 pairs of observations of this matrix, i.e. I need to remove a 20x2 matrix of the population matrix (100000x2). but I need a 20x2 matrix is chosen randomly.

When I insert to the SAMPLE function within the code, the following appears Feedback: "ERROR: Invocation of unresolveed module SAMPLE"

What am I doing wrong?

SAS Super FREQ
Posts: 4,239

Re: FUNCTION SAMPLE

You didn't study for very long.

Define arrays with curly braces: {};

Assignment is of the form

NewVar = Function(arg1, arg2);

PROC IML;

N = 100000;

MEAN = {0.074, 0.1274};

COV = {0.000302 0.000581, 0.000581 0.00156};

CALL RANDSEED (321);

P = RANDNORMAL(N, MEAN, COV);

idx = SAMPLE(1:N, 20, "noreplace");

the = P[idx,];

print the;

Occasional Contributor
Posts: 11

Re: FUNCTION SAMPLE

Dear Rick,

The objective of this study is to evaluate whether the index formed by the division of these two variables has a normal distribution.

The mean, variance and covariance used for the simulation of the data came from fieldwork (Animal Science - Growing cattle, n = 41).

For this reason I'm simulated a  matrix Nx2 using PROC IML, but never worked with this procedure in SAS.

The intention was to create a simulation of the population with mean, variance and covariance equal gives the sample collected in the field.

I would like to take a sample of this population to test normalizade variables and the index formed by the division of the two.

Follows the complete code:

PROC IML;

N=100000;

MEAN={0.074, 0.1274};

COV={0.000302 0.000581,0.000581 0.00156};

CALL RANDSEED(321);

P = RANDNORMAL(N,MEAN,COV);

CREATE ESTRUTURA FROM P; APPEND FROM P; CLOSE ESTRUTURA;

RUN;

DATA DATA_A; SET ESTRUTURA; RENAME COL1=ELM COL2=EMM;

KM=COL1/COL2;

RUN;

PROC PRINT DATA=DATA_A; RUN;

PROC CORR DATA=DATA_A;

VAR ELM EMM;

RUN;

ODS GRAPHICS ON;

PROC UNIVARIATE DATA=DATA_A NORMAL;

VAR ELM EMM KM;

HISTOGRAM / NORMAL;

RUN;

ODS GRAPHICS OFF;

using the programming provided by you, the message: "ERROR: Invocation of unresolveed module SAMPLE", appeared again when I tried to remove the sample.

I'm sorry by my ignorance, but I'm since the study started Monday this week, but I'm struggling.

Solution
‎09-11-2014 03:00 PM
SAS Super FREQ
Posts: 4,239

Re: FUNCTION SAMPLE

Here is a longer explanation of using the SAMPLE function: Sample without replacement in SAS - The DO Loop

The SAMPLE function was introduced in SAS/IML 12.1 (August 2012, SAS 9.3m2).

You can use the following statements to find your version of SAS:

%put SYSVLONG = &SYSVLONG;

If you are using an old version of SAS, you can use PROC SURVEYSELECT, as shown in the blog article.

With regards to your ultimate question (distribution of the ratio), there has been a lot of work done on this question.  You might be interested in reading Hinkley's theoretical treatment

and this more modern approach

http://www.jstor.org/stable/2987992

Occasional Contributor
Posts: 11

Re: FUNCTION SAMPLE

Dear Rick,

Thanks for attention,

My SAS is version 9.2, my university (Federal University of Viçosa - Brazil) has a license for SAS 9.4 but can not install it on Windows 8.1. Feedback returns the following error: "The SAS Deployment Wizard is not able to proceed with the installation The possible reason is que order the software you are installing was subsetted from the original order, but the operating system you are installing the software on was not included in the subset process. Provide this error message to the person who gave you the software. If this does not resolve the problem, contact SAS Technical Support for assistance "

Yes my correlation is 0.85

When reading some topics written by you thought it would be possible to use the function to RANDGEN such, but my attempts were not successful.

Yes I will read about the PROC SURVEYSELECT and see if you can use it.

Best regards.

SAS Super FREQ
Posts: 4,239

Re: FUNCTION SAMPLE

So I'm curious: Why do you need to generate a sample with 10000 random variates and then sample 20 of them? Why can't you just sample 20 directly from the distribution? Seem like an equivalent formulation is

P = randnormal(20, mean, cov);

and it eliminates the whole SAMPLE problem

Occasional Contributor
Posts: 11

Re: FUNCTION SAMPLE

I think like you, but my PhD advisor wants me to take a sample swatch to be able to take the test.

Occasional Contributor
Posts: 11

Re: FUNCTION SAMPLE

Dear Rick,

Thanks the PROC SURVEYSELECT worked perfectly.

🔒 This topic is solved and locked.

Discussion stats
• 11 replies
• 986 views
• 0 likes
• 3 in conversation