Turn on suggestions

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

Showing results for

- Home
- /
- Learn SAS
- /
- SAS Software for Learning Community
- /
- Need help fixing my code, the errors are not making sense to me.

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**.
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 04-11-2024 05:53 PM
(550 views)

So I'm trying to create a sample using SAS. I'm using a Sample Size formula defined below. But I get errors saying that the Eval has characters instead of numbers but I dont think it's true, also one of the other errors are in my options for the proc Surveyselect it says they don't belong? but I think they do, based on the Proc Surveyselect resources. any help would be appreciated.

Here is the Code, I'm using the Pg2 library from the 2nd lesson:

%let Z = 1.96;

%let P = 0.05;

%let E = 0.05;

proc sql noprint;

select count(*) into :N from pg2.class_birthdate;

quit;

%let Sample_Size = %eval((&N * ((&E * (1 - &E)) / (&P / &Z) ** 2)) / (((&E * (1 - &E)) / ((&P / &Z) ** 2)) + &N - 1));

%put Sample Size: &Sample_Size;

data SampledClass;

proc surveyselect data=pg2.class_birthdate

method=srs

out=SampledClass

sampsize= &sample_size

seed=1234;

run;

proc print data=SampledClass;

run;

1 ACCEPTED SOLUTION

Accepted Solutions

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

In which case it might be better to use %SYSFUNC(CEIL()) instead of %SYSEVALF().

%let Z = 1.96; %let P = 0.05; %let E = 0.05; %let N=12345 ; %let Sample_Size=%sysfunc(ceil((&N * ((&E * (1 - &E)) / (&P / &Z) ** 2)) / (((&E * (1 - &E)) / ((&P / &Z) ** 2)) + &N - 1))); %put Sample Size: &Sample_Size;

Result

1590 %put Sample Size: &Sample_Size; Sample Size: 73

7 REPLIES 7

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

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

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

In which case it might be better to use %SYSFUNC(CEIL()) instead of %SYSEVALF().

%let Z = 1.96; %let P = 0.05; %let E = 0.05; %let N=12345 ; %let Sample_Size=%sysfunc(ceil((&N * ((&E * (1 - &E)) / (&P / &Z) ** 2)) / (((&E * (1 - &E)) / ((&P / &Z) ** 2)) + &N - 1))); %put Sample Size: &Sample_Size;

Result

1590 %put Sample Size: &Sample_Size; Sample Size: 73

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

Thank you! I'm silly I knew they had to be integers, I knew i was supposed to round the answer because that's how i currently do it in excel.

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

With @JackieJ_SAS's comment, perhaps you want the SAMPRATE , as in a percentage of observations, instead of SAMPSIZE, a specific number of observations?

Note: **any time** you get errors best practice on this forum is to copy the LOG text with the submitted code and all notes, messages, warnings or errors. Then on the forum open a text box and paste the copied log text.

The text box will preserve the text layout and position of diagnostic information SAS often supplies in error messages as the main message windows will reformat pasted text reducing the usefulness of the text somewhat.

Also the complete log text is important. We often have people ask about an "error" that is not indeed an error but a warning or sometimes just information.

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

Thank you for the tip! I'll follow this to include the log next time!. The formula evaluates to a specific number so Sampsize is what i wanted to use. It was just me forgetting to round the number back to a whole integer.

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

Thank you! I knew I was supposed to round it. I'm just very forgetful.

**Available on demand!**

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

Upcoming Events

- PharmaSUG 2024 | 19-May-2024
- SAS Halifax Region User Group (SHRUG) Meeting | 23-May-2024
- What’s New in SAS Optimization? | 23-May-2024
- Montreal SAS User Group (MONSUG) Meeting | 29-May-2024
- Club des utilisateurs SAS de Québec | 30-May-2024
- Optimizing Logistics Operations Using Customized Solutions | 04-Jun-2024
- Toronto SAS Users' Community Luncheon | 04-Jun-2024