Turn on suggestions

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

Showing results for

Options

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

🔒 This topic is **solved** and **locked**.
Need further help from the community? Please
sign in and ask a **new** question.

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

Posted 09-11-2014 12:48 PM
(1949 views)

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

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

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.

11 REPLIES 11

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

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

--

Paige Miller

Paige Miller

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

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.

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

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

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

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?

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

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;

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

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.

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

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.

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

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.

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

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

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

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

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

Dear Rick,

Thanks the PROC SURVEYSELECT worked perfectly.

**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.

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.