BookmarkSubscribeRSS Feed
mrzlatan91
Obsidian | Level 7

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?

 

2 REPLIES 2
PaigeMiller
Diamond | Level 26

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
ballardw
Super User

@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?

 

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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