DATA Step, Macro, Functions and more

problem with the format

Reply
Contributor
Posts: 22

problem with the format

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!
Super Contributor
Super Contributor
Posts: 3,174

Re: problem with the format

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.
Frequent Contributor
Posts: 106

Re: problem with the format

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
Contributor
Posts: 22

Re: problem with the format

Thanks Robert,
I have followed your instructions and I have solved the problem.
Ask a Question
Discussion stats
  • 3 replies
  • 125 views
  • 0 likes
  • 3 in conversation