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;
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.
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.
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.
thank you very much;
it works
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.
thanks a lot
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.