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-wordmark-2025-midnight.png

Register Today!

Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.


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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

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