Re: Newbie SAS Array problem (take 2) #2

Hi Machelle,

Nice, good. But you should also declare your arrays dxnum and diagnum as
being of character type. And I would even completely avoid this kind of
solution. I would use a format instead (with some arrays or some macro

Create a format for your 46 diagnose codes, like:
  VALUE $DiagFmt
  '4270' = 'Paroxysmal supraventricular tachycardia'
  .............and so on.............

And if it is just for presentation then never create a variable with the
textual diagnoses, but use the code variables (dx#) instead with the
format. If you really need a variable like DiagName# then either use an
array or use macro code:

Array (*untested*):
Array dxnum{25} $ dx1-dx25;
ARRAY diagname(25) $70 diag1-diag25;
do j=1 to 25;
  DiagName(J) = PUT (DXnum(J), DiagFmt.);

Macro code (in a macro) (*untested*):
%DO J = 1 %TO 25;
  DiagName&J = PUT (DX&J, DiagFmt.);

HTH, good luck.

Regards - Jim.
Jim Groeneveld, Netherlands, Statistician and SAS programmer

My new computer is about to get used to SAS by mind reading.

[common disclaimer]

On Sun, 8 Jan 2006 18:18:34 -0800, machellewilchesky@GMAIL.COM wrote:

>{My apologies if this thread appears twice... I originally attempted
>posting it at approximately 5:00 pm this evening, but it has yet to
>appear and I am thus making another attempt...}
>Hi SAS-L'ers...
>I have a confession to make... I have been avoiding using Arrays for
>years and today is the day when I have put my foot down and have tried
>to face my fears and learn how
>to use them for once and for all.
>I have a clinical dataset with 25 diagnosis codes (A primary diagnosis
>and 24 potential secondary diagnosis variables). For each of these 25
>diagnosis codes I want to be able to define a new variable called
>Diagname which corresponds to one of 46 possibilities.
>In a non-array world, my program would look something like this:
>data one;
>set x;
>if dx1  ='4270'  then  diagname1='Paroxysmal supraventricular
>if dx2  ='4270'  then  diagname2='Paroxysmal supraventricular
>if dx25 ='4270'  then  diagname25='Paroxysmal supraventricular
>if dx1  ='4274' then diagname1='Ventricular Fibrillation and flutter'
>if dx2  ='4274' then diagname2='Ventricular Fibrillation and flutter'
>if dx25  ='4274' then diagname25='Ventricular Fibrillation and flutter'
>Since I have 25 diagnoses *46 diagnosis codes, the full program would
>require 1,150 lines of code, and so this seems like a likely candidate
>for array processing. I have tried several ways to  make it work but
>I'm obviously missing something... An example of code I have tried is
>data one;
>set x;
>attrib diagname1-diagname25 format=$70.;
>Array dxnum{25} dx1-dx25;
>Array diagnum(25) diag1-diag25;
>Array ICD{46}$ ('4270' '4271' '4272' '4273' '4274' '4275' '4276'
>               '4278' '4279' 'I471' 'I472' 'I479' 'I480' 'I481'
>               'I490' 'I460' 'I469' 'I491' 'I492' 'I493' 'I494'
>               'I470' 'I471' 'I495' 'I498' 'I499' 'R000' 'R001' 'R008'
>               'R012' 'I499' 'I518' '4289' 'I509' '4299' '4260' 'I442'
>               '7853' '4298' 'I231' 'I232' 'I233' 'I2380' 'I2381'
>'I2382' 'I2388');
>Array Diagname{46} $ ('Paroxysmal supraventricular tachycardia'
>'Paroxysmal ventricular tachycardia'
>'Paroxysmal tachycardia, unspecified'
>'Atrial Fibrillation and flutter'
>'Ventricular Fibrillation and flutter'
>'Cardiac Arrest'
>'Premature beats'
>'Other specified cardiac dysrhythmias'
>'Cardiac dysrhythmia, unspecified'
>'Supraventricular tachycardia'
>'Ventricular tachycardia'
>'Paroxysmal tachycardia, unspecified'
>'Atrial fibrillation and flutter'
>'Ventricular fibrillation and flutter'
>'Cardiac arrest'
>'Cardiac arrest with successful resuscitation'
>'Cardiac arrest, unspecified'
>'Atrial premature depolarization'
>'Junctional premature depolarization'
>'Ventricular premature depolarization'
>'Other and unspecified premature depolarization'
>'Re-entry ventricular arrhythmia'
>'Supraventricular tachycardia'
>'Sick sinus syndrome'
>'Other specified cardiac arrhythmias'
>'Cardiac arrhythmia, unspecified'
>'Tachycardia, unspecified'
>'Bradycardia, unspecified'
>'Other and unspecified abnormalities of heart beat'
>'Other cardiac sounds'
>'Cardiac arrhythmia, unspecified'
>'Other ill-defined heart diseases'
>'Heart failure, unspecified'
>'Heart failure unspecified'
>'Heart disease, unspecified'
>'Atrioventricular block, complete'
>'Atrioventricular block complete'
>'Other abnormal heart sounds'
>'Other ill-defined heart diseases'
>'Atrial septal defect as current complication following Acute MI'
>'Ventricular septal defect as current complication following Acute MI'
>'Rupture of cardiac wall without haemopericardium as following Acute
>'Papillary muscle dysfunction following acute MI'
>'Pericarditis following acute myocardial infarction'
>'Postmyocardial infarction angina'
>'Other complications following acute MI');
>do j=1 to 25;
>do k=1 to 46;
>if  dxnum{j}= icd{k} then diagnum{j}=diagname{k};
>Any and all points in the right direction would be appreciated!
>Thanks in advance,
jim1stat (510)
1/9/2006 9:35:42 AM
comp.soft-sys.sas 142828 articles. 3 followers. Post Follow

2 Replies

Similar Articles

[PageSpeed] 13

Hi Dietrich and Eric

Thanks for the replies.
I actually *do* need variables and not just labels for several reasons
(onw of which is because I have to then perform an index function on
the diagnosis names later on).

In any case whether or not I could 'get away with' using something
besides arrays, like I said.. I had decided that enough was enough and
that I was going to tackle this array phobia I have had for once and
for all. I therefore thank you for your helpful comments :)

SAS Macro language is next... (oh oh... :) )

Thanks again, 


1/9/2006 11:44:28 AM
Thanks Jim!

1/9/2006 2:04:21 PM