BookmarkSubscribeRSS Feed
_LB
Fluorite | Level 6 _LB
Fluorite | Level 6
Hello all!

Hopefully someone can help me debug this program.

Right below is the starting mock table that outlines the problem...
(The tables don't render properly)
Patient_Number Day1 Day2 Day 3
123 A B A
124 A B C

The letters represent codes that have to be converted into their own variables and then summed so that what you have is:

Patient_Number Day1 Day2 Day 3 A B C
123 A B A 2 1 0
124 A B C 1 1 1

The first part of the macro creates the list and then there is an indirect call to it.
The second part attempts to create an array for every code to accomplish the above. The codes are part of a dataset...

the macro almost works as it does pass each code through. Except I am running into a hitch at the last moment. The problem is coming down to an improper "when" and/or improper do blocks somewhere.

The code and then part of the log follows below. Any assistance would be greatly appreciated!

THIS PART WORKS!
%macro split (data=, var=);
proc sort data=&data(keep=&var) out=values nodupkey;
by &var;
run;
data _null_;
set values end=last;
call symputx('site'||left(_n_),&var);
if last then call symputx('count',_n_);
run;
THIS PART DOES NOT!
DATA ALLDATA;
MERGE PTS INPUTDATA;
BY MR_;
select(&var);
%do i=1 %to &count;
when("&&site&i") %do;
array Cod&&site&i [7] Day1-Day7;
Code&&site&i=0;
DO I=1 to 7;
If Cod&&site&i="&&site&i" then Code&&site&i=Code&&site&i+1;
end;
%END;

%END;
drop I;
run;


%mend split;
%split(data=Codes, var=code)


Program Log:

DATA ALLDATA;
MPRINT(SPLIT): MERGE PTS INPUTDATA;
MPRINT(SPLIT): BY MR_;
MPRINT(SPLIT): select(code);
NOTE: Line generated by the invoked macro "SPLIT".
5 array Cod&&site&i [7] Day1-Day7; Code&&site&i=0; DO I=1 to 7; If
-----
180
5 ! Cod&&site&i="&&site&i" then Code&&site&i=Code&&site&i+1; end;
MPRINT(SPLIT): when("A") array CodA [7] Day1-Day7;
MPRINT(SPLIT): CodeA=0;
ERROR: Expecting "WHEN", "OTHERWISE", or "END".
MPRINT(SPLIT): DO I=1 to 7;
MPRINT(SPLIT): If CodA="A" then CodeA=CodeA+1;
MPRINT(SPLIT): end;
7 REPLIES 7
sbb
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10
Your %DO needs to be a DATA step DO statement -- to go with your SELECT/WHEN/END/OTHERWISE/END paragraph construct.

Scott Barry
SBBWorks, Inc.
_LB
Fluorite | Level 6 _LB
Fluorite | Level 6
Scott;
Thanks for the tip! Got me one inch closer. Now it seems to run through but I get the errors:
NOTE: Character values have been converted to numeric values at the places given by:
(Line):(Column).
1:1 1:1 1:1 1:1 1:1 1:1 1:1 1:1 1:1 1:1 1:1 1:1 1:1 1:1 1:1
1:1 1:1 1:1 1:1 1:1 1:1 1:1 1:1 1:1 1:1 1:1 1:1 1:1 1:1 1:1
1:1 1:1 1:1 1:1 1:1 1:1 1:1 1:1 1:1
NOTE: Variable code is uninitialized.
NOTE: Invalid numeric data, 'A' , at line 1 column 1.

So it works for the first code but then stops...still playing with it.

Lawrence
sbb
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10
Suggest you have a look at PROC TRANSPOSE, instead.

Scott Barry
SBBWorks, Inc.
_LB
Fluorite | Level 6 _LB
Fluorite | Level 6
A less elegent solution but doable. Just very close with this. Thank you for the suggestion...
Cynthia_sas
SAS Super FREQ
Hi:
Regarding this:
(The tables don't render properly)


when you want to show code or the SAS log or a mock table where it would be swell if everything lined up, like this:
[pre]
Patient_Number Day1 Day2 Day3
123 A B A
124 A B C
[/pre]

All you need to do is surround your code and/or your table with the PRE tags. Only these are not HTML <PRE> tags, the tag is
squarebracket-PRE-squarebracket_close
squarebracket-/PRE-squarebracket_close or

(PRE) and (/PRE)

except where I have the (, you would put [ and where I have the ), you would put ] -- that will tell the forum text editor and posting manager to NOT format anything within these special PRE tags.

cynthia
_LB
Fluorite | Level 6 _LB
Fluorite | Level 6
Thanks for how-to...I am brand spanking new to the forum wiull abide by this in the future...
~LB
_LB
Fluorite | Level 6 _LB
Fluorite | Level 6
I would like to thank Scott again for his help. Figured out the last part and now it works!

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

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
  • 7 replies
  • 793 views
  • 0 likes
  • 3 in conversation