BookmarkSubscribeRSS Feed
TMorville
Calcite | Level 5
Hi everyone and merry xmas!

I have a quick question, that i don't quite know how to google.

I have a datastep with arrays in it:

data rotate;
set retain_test;
by bp_2;
retain numabb17-numabb43;
array Anumabb(17:43) numabb17-numabb43;
if first.bp_2 then do;
do i = 17 to 43;
Anumabb = .;
end;
end;
Anumabb(week) = numabb;
if last.bp_2 then output;
drop week i;
run;

This is just part of the code. What i would like to do, is to have two variables for the weeknumbers. So instead of writeing 17 and 43, i predefine them above, and then i can change them as i wish to.

Im thinking something like this:

startweek = 17
endweek = 43

data rotate;
set retain_test;
by bp_2;
retain numabb(startweek)-numabb(endweek);
array Anumabb((startweek):(endweek) numabb(startweek)-numabb(endweek);
if first.bp_2 then do;
do i = (startweek) to (endweek);
Anumabb = .;
end;
end;
Anumabb(week) = numabb;
if last.bp_2 then output;
drop week i;
run;

Any ideas?

Thanks!
Toby Message was edited by: TMorville
5 REPLIES 5
Patrick
Opal | Level 21
Hi

Below code probabely does what you're after:

proc sql noprint;
select cats(max(week)), cats(min(week)) into :maxweek, :minweek
from retain_test
;
quit;

/* alternative to SQL above - but less dynamic:
%let minweek=17;
%let maxweek=43;
*/

data rotate;
set retain_test;
by bp_2;
array Anumabb(*) 8 numabb&minweek. - numabb&maxweek.;
retain numabb&minweek. - numabb&maxweek.;

if first.bp_2 then call missing(of Anumabb(*));

Anumabb(week) = numabb;

if last.bp_2 then output;

drop week;
run;


I assume in your real code there are more transformations.
If not then Proc Transpose might be another way to go.

proc transpose data=retain_test out=rotate prefix=numabb;
by bp_2;
id week;
var numabb;
run;


HTH
Patrick

Message was edited by: Patrick added missing SELECT to SQL


Message was edited by: Patrick
TMorville
Calcite | Level 5
Hi Patrick, and thanks for the reply.

I can't get the sql to work, it says that the "cats" argument is unknown or used out of order.

Im not very experienced with sql, so i have no idea where to start troubleshooting.

-t
sbb
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10
The CATS (and other CAT-related functions were added with SAS 9), however I also notice that the PROC SQL code is missing a "SELECT".

Scott Barry
SBBWorks, Inc.

Suggested Google advanced search argument, this topic / post:

proc sql site:sas.com
Ksharp
Super User
Hi.
You can remove cats(), directly use max(week).
I think Patrick used function cats() is just to want to delete the surplus blanks.
Actually ,the macro variable will automatically remove the heading and trailing blanks.


Sorry. I am wrong. Actually Proc Sql will keep heading and trailing blanks for the single macro variable.


Ksharp Message was edited by: Ksharp
art297
Opal | Level 21
Toby,

I'm surprised that anyone could even attempt to answer your question without knowing what you incoming data look like and how you want the resulting data to appear.

Some example data, in the form of a datastep, would definitely help.

Art

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 5 replies
  • 860 views
  • 0 likes
  • 5 in conversation