BookmarkSubscribeRSS Feed
reone
Calcite | Level 5
Hi to all;
I have created this code in SAS:


data prova;

numeroRandom = round(rand('unifor')*(&numeroOsservazioni+1));
if numeroRandom = &numeroOsservazioni+1 then do;
numeroRandom = &numeroOsservazioni;
end;

set clientiposta(
firstobs = numeroRandom
obs = numeroRandom
);


run;


I have a problem when I define the firstobs and obs because the log shows the problem in that point. Where i mistake?

thanks!
3 REPLIES 3
sbb
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10
Please reply again and this time include a "pasted SAS log" record of what problem / error messages you are getting. It appears you are using SAS macro variable(s), so you will want to include as much information about your program execution as possible, by including this command in your SAS script to add as much diagnostic output to the SAS log, revealing your program flow as possible:

OPTIONS SOURCE SOURCE2 MACROGEN SYMBOLGEN MPRINT;

Also, sharing information about your SAS environment will help as well, such as has your program ever run successfully (is it new or existing?), what OS platform are you running SAS on, is SAS installed local or on a "connected" server, maching, and also SAS version info.

Also, I believe you have some challenges using the SAS SET statement and those dataset options when you are attempting to compute the first-observations to start and the observation-count to execute.

Scott Barry
SBBWorks, Inc.
Robert_Bardos
Fluorite | Level 6
Timing problem. FIRSTOBS and OBS options are evaluated at data step compile time so in your code the value of numeroRandom is not yet known. Try it like this:
[pre]
%let numeroosservazioni=19 ; /* I used this for my test */
data _null_ ;
numeroRandom = round(rand('unifor')*(&numeroOsservazioni+1));
if numeroRandom = &numeroOsservazioni+1 then do;
numeroRandom = &numeroOsservazioni;
end;
call symput('_nr',put(numeroRandom,best.)) ;
stop ;
run ;

%put NumeroOsservazioni <&numeroosservazioni> ;
%put _nr <&_nr> ;
data prova;
set sashelp.class /* I used this for my test */
(firstobs = &_nr
obs = &_nr
);

run;
[/pre]

Hope this helps
Robert
reone
Calcite | Level 5
Thanks Robert,
I have followed your instructions and I have solved the problem.

sas-innovate-2024.png

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.

 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 3 replies
  • 714 views
  • 0 likes
  • 3 in conversation