Recursive Macro or Using a Loop

Moderators: statman, Analyst Techy, andris, Fierce, GerineL, Smash

Posts: 1
Joined: Tue Nov 17, 2015 7:25 am

Recursive Macro or Using a Loop

Postby AnniekBrink » Tue Nov 17, 2015 7:59 am


I am currently having a database with labvalues from patients from their visits to the hospital. My current problem is that all the different values are coded by moment of retrieval, while I would like to list them according to parameter (for example, Potassium, Hemoglobin, Sodium etc. etc.). It is even more difficult because I have different parameters both in blood and in urine (for example).

So what I would like to do is:
When X=blood and Y=Sodium then I want to move the Result to a new variable called: SodiumBlood.

A visual representation of how my database looks now and how I would like it to look is the following:

Patient Material Parameter Result Unit Material 2 Parameter 2 Result 2 Unit 2 Material 3 Parameter 3 Result 3 Unit3 etc.
X1 Blood Sodium 133 mmol/L
X2 Blood Hemoglobine 7.8 mmol/L
X3 Blood Potassium 3.7 mmol/L
X4 Urine Sodium 150 mmol/L
X5 Blood Potassium 4.3 mmol/L

How I would like it to look:
Material Parameter Result Unit SodiumBlood Hemoglobine PotassiumBlood SodiumUrine
Blood Sodium 133 mmol/L 133 . . .
Blood Hemoglobine 7.8 mmol/L . 7.8 . .
Blood Potassium 3.7 mmol/L . . 3.7 .
Urine Sodium 150 mmol/L . . . 150
Blood Potassium 4.3 mmol/L . . 4.3 .

In which patientcases will not be mixed.
I have been thinking about using recursive macros or making a loop, but honestly I do not know how.

Maybe one of you can help me?

Yours sincerely,

Anniek Brink
Posts: 1477
Joined: Tue Jun 10, 2008 4:50 pm

Re: Recursive Macro or Using a Loop

Postby GerineL » Tue Nov 17, 2015 11:17 am

Not entirely sure what it is you want, so if I understand correctly, you want besides the variable that is already in there, a variable that only holds a certain value if that row is that test.
Is this correct?

If there is not too many types of results, you could just write an if-function.
if (material = "Blood" & Parameter = "Sodium") SodiumBlood = result.
if (Parameter = "Hemoblobine") Hemoglobine = result.
Posts: 119
Joined: Wed May 25, 2011 7:07 am

Re: Recursive Macro or Using a Loop

Postby JonPedersen » Tue Nov 17, 2015 3:39 pm

If I am not completely mistaken you should be able to use the Variables to cases command for this.
PS: recursive macros do not work. You can do recursion in Python, but that is sparrow hunting with a very big battleship. You can actually also do what you want in a simple loop that produce several datasets that you merge afterwards (what I sometimes do when I get exasperated by the varstocases syntax...)

Who is online

Users browsing this forum: No registered users and 1 guest