DATA Step, Macro, Functions and more

Problem with Macrovariable

Reply
Contributor
Posts: 20

Problem with Macrovariable

[ Edited ]

Hi guys, unfortunately I have a problem using Macrovariables. My datasets look like this:

 

data work.a;

input index $ id $;

datalines;

1 124

2 425

3 364

4 353
5 858
6 954

;

run;

data work.b;

input date $ value1 $ value2 $ value3 $ value4 $ value5 $ value6 $;

datalines;

01DEC05 1 5 5 5 3 1

01DEC06 1 4 5 8 8 1

02DEC06 1 2 3 2 2 1

05DEC06 1 1 2 1 2 9

01JAN07 1 1 1 1 1 .

02JAN07 1 2 1 . 1

;

run;

 

Note, that every index of Table a represents a corresponding value column of table b.

That means, that e.g. the values of ID 124 (Index 1) are represented in the column of table b.

Now, in my macro, I do some checks and want to set some specific value columns to missing.

To try this, I used the following code:

 

(First, I selected the ID in :lostid in a step before, but this has worked before)

 

proc sql;

select index into :currIndex from work.a where id = &lostid;

quit;

 

after that, I know the index of the id and want to add its column:

 

data work.b;

set work.b;

value&currIndex = .;

run;

 

 

Unfortunately, I´m getting the following error: Statement is not valid or it is used out of proper order. Does anyone have a suggestion for my problem?

 

Respected Advisor
Posts: 3,278

Re: Problem with Macrovariable

Posted in reply to mrzlatan91

Run the program again, but put the following line at the top of your program.

 

options mprint;

Then show us the SASLOG, if you can't figure out the error yourself.

--
Paige Miller
Super User
Posts: 13,941

Re: Problem with Macrovariable

Posted in reply to mrzlatan91

@mrzlatan91 wrote:

Hi guys, unfortunately I have a problem using Macrovariables. My datasets look like this:

 

Note, that every index of Table a represents a corresponding value column of table b.

That means, that e.g. the values of ID 124 (Index 1) are represented in the column of table b.

Now, in my macro, I do some checks and want to set some specific value columns to missing.

To try this, I used the following code:


How is 124 "represented" in which column of table b?

 

When you get an error copy the code submitted and the error messages from the log and paste into a code box opened using the forum {I} menu icon to preserve formatting of the error messages.

 

 

Show what your desired output would look like for your examples.

And explain your rules a little. You show a macro variable, &lostid,  but not it's value. So we don't know what you might actually be looking for. Is &lostid ever likely to be duplicated in different records of work.a? If so your sql will always select the first index where it appears as written.

 

 

Your example work.a would have ID value of 3535 for index 4. Is that actually what you intended?

 

Ask a Question
Discussion stats
  • 2 replies
  • 48 views
  • 0 likes
  • 3 in conversation