From: Nathalie Billaudeau on
I want to create a dataset for each individual (street_1 to
street_7292 with id « incidentid » from 1 to 7292) with the
instruction output, but this program doesn’t work. Particularly, SAS
does not like “data Street_1-Street_7292 ». Could someone help me?
Best regards,
Nathalie


%macro test;
%local i;
data Street_1-Street_7292;
set Street;
%do i=1 %to 7292;
if incidentid=&i then output Street_&i;
%end;
run;
%mend;
%test;
From: Ya on
On Jun 9, 9:18 am, Nathalie Billaudeau <nathaliebillaud...(a)gmail.com>
wrote:
> I want to create a dataset for each individual (street_1 to
> street_7292 with id « incidentid » from 1 to 7292) with the
> instruction output, but this program doesn’t work. Particularly, SAS
> does not like “data  Street_1-Street_7292 ». Could someone help me?
> Best regards,
> Nathalie
>
> %macro test;
> %local i;
> data  Street_1-Street_7292;
>  set Street;
>  %do i=1 %to 7292;
>  if incidentid=&i then output Street_&i;
>  %end;
>   run;
>  %mend;
>  %test;

Change to this should work:

%macro test;
%local i;
%do i=1 %to 7292;
data Street&i;
set Street;
if incidentid=&i then output;
run;
%end;
%mend;

%test;

HTH

Ya

From: barryd on
On Jun 9, 5:18 pm, Nathalie Billaudeau <nathaliebillaud...(a)gmail.com>
wrote:
> I want to create a dataset for each individual (street_1 to
> street_7292 with id « incidentid » from 1 to 7292) with the
> instruction output, but this program doesn’t work. Particularly, SAS
> does not like “data  Street_1-Street_7292 ». Could someone help me?
> Best regards,
> Nathalie
>
> %macro test;
> %local i;
> data  Street_1-Street_7292;
>  set Street;
>  %do i=1 %to 7292;
>  if incidentid=&i then output Street_&i;
>  %end;
>   run;
>  %mend;
>  %test;

Nathalie,

I don't believe that the data step allows the '-' to be used to
signify the range of dataset names that you want.

Just put the generation of the dataset names into a similar loop to
that around your IF statement.

For example:

%macro test;
%local i;
data
%DO i=1 %TO 10;
Street_&i
%END;
;
set Street;
%do i=1 %to 10;
if incidentid=&i then output Street_&i;
%IF &i <10 %THEN %STR(ELSE);
%end;
run cancel;
%mend;

In the code above I've used a value of 10 for testing purposes. I've
also included the ELSE keyword to change your statements to IF ...
THEN ... ELSE constructs. This should make things more efficient,
though depending on the data it might make little difference.

Regards,

BPD