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

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.

1 ACCEPTED SOLUTION

Accepted Solutions
Rick_SAS
SAS Super FREQ

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

http://stevereads.com/papers_to_read/on_the_ratio_of_two_correlated_normal_random_variables.pdf

and this more modern approach

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

Your correlation is 0.85.

View solution in original post

11 REPLIES 11
PaigeMiller
Diamond | Level 26

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

--
Paige Miller
bonfa
Calcite | Level 5

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.

Rick_SAS
SAS Super FREQ

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,];

bonfa
Calcite | Level 5

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?

Rick_SAS
SAS Super FREQ

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;

bonfa
Calcite | Level 5

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.

Rick_SAS
SAS Super FREQ

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

http://stevereads.com/papers_to_read/on_the_ratio_of_two_correlated_normal_random_variables.pdf

and this more modern approach

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

Your correlation is 0.85.

bonfa
Calcite | Level 5

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.

Rick_SAS
SAS Super FREQ

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

bonfa
Calcite | Level 5

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

bonfa
Calcite | Level 5

Dear Rick,


Thanks the PROC SURVEYSELECT worked perfectly.

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

Multiple Linear Regression in SAS

Learn how to run multiple linear regression models with and without interactions, presented by SAS user Alex Chaplin.

Find more tutorials on the SAS Users YouTube channel.

From The DO Loop
Want more? Visit our blog for more articles like these.
Discussion stats
  • 11 replies
  • 1916 views
  • 0 likes
  • 3 in conversation