BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
farzad14000
Calcite | Level 5

hello to everyone;

somebody knox why this code dos not work please,

data test33;
set perso.test;

by epci;
array sex (i) SEXE1_AGED100000-SEXE1_AGED100100;
do i=1to 101;
end;
array sexage(i) _NUMERIC_;
do i=1to 101;
end;


if first.epci then sexage(i)=0;
sexage(i)+sex(i);
i=1to101;

if last.epci ;


run;
proc print data=test33;
run;

 

1 ACCEPTED SOLUTION

Accepted Solutions
Astounding
PROC Star

This program has very few pieces that would work.  The best thing you did is accurately count the number of elements in your array.  I'm going to sketch out valid code for what I think you are trying to do here.

 

data test33;
set perso.test;

by epci;
array sexage {101} sexage000 - sexage100;
array sex {101} SEXE1_AGED100000-SEXE1_AGED100100;
if first.epci then do i=1 to 101;
   sexage{i} = 0;
end;
do i=1 to 101;
   sexage{i} + sex{i};
end;
if last.epci ;
run;
proc print data=test33;
run;

But I'm guessing.  It would be easier if you would describe which variables you already have, which variables you would like to create, and what the logic is for creating them.

View solution in original post

5 REPLIES 5
VDD
Ammonite | Level 13 VDD
Ammonite | Level 13

because the design has not been thought out.

you have do loops that do nothing.

you have assignment outside of where you would obtain a value.

 

Astounding
PROC Star

This program has very few pieces that would work.  The best thing you did is accurately count the number of elements in your array.  I'm going to sketch out valid code for what I think you are trying to do here.

 

data test33;
set perso.test;

by epci;
array sexage {101} sexage000 - sexage100;
array sex {101} SEXE1_AGED100000-SEXE1_AGED100100;
if first.epci then do i=1 to 101;
   sexage{i} = 0;
end;
do i=1 to 101;
   sexage{i} + sex{i};
end;
if last.epci ;
run;
proc print data=test33;
run;

But I'm guessing.  It would be easier if you would describe which variables you already have, which variables you would like to create, and what the logic is for creating them.

farzad14000
Calcite | Level 5

thank you very much;

it works Man Happy

PGStats
Opal | Level 21

It looks like you are trying to do something like this:

 

data test33;
set perso.test;
by epci;
array sex SEXE1_AGED100000-SEXE1_AGED100100;
array sexage {101};
retain sexage:;
if first.epci then 
    do i=1 to 101;
        sexage{i}=0;
        end;
do i=1 to 101;
    sexage{i}=sexage{i}+sex{i};
    end;
if last.epci then output;
run;

But that's just a wild guess.

 

try to get the simple parts working first - arrays - -do loops -  - BY processing -  before combining them.

PG
farzad14000
Calcite | Level 5

thanks a lot

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

How to connect to databases in SAS Viya

Need to connect to databases in SAS Viya? SAS’ David Ghan shows you two methods – via SAS/ACCESS LIBNAME and SAS Data Connector SASLIBS – in this video.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 5 replies
  • 951 views
  • 0 likes
  • 4 in conversation