BookmarkSubscribeRSS Feed
deleted_user
Not applicable
Any suggestions on how to get 'hs' to resolve correctly?
data test;
input a1_1 a2_1 a3_1;
cards;
1 2 3
3 4 5
;
run;

%macro symps;

data test2 ( keep = a1 );
set test;
array a1_(1) a1_1;

call symput( 'hs' , trim( left( _n_ ) ) );
a1 = a&hs._1; /*i want this to resolve to something like a1=a2_1 */
put _all_;
run;

%mend symps;

%symps;
proc print data = test2;
run;
5 REPLIES 5
sbb
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10
Best to explain in your words (and illustrate both INPUT and desired OUTPUT sides) what it is that you want to accomplish.

Scott Barry
SBBWorks, Inc.
deleted_user
Not applicable
Sure. I want to assign the value contained in a3_1 to a new variable. But i need to reference an array that has the form aN_(index), where N = 1, 2, ... 10. The 'N' is determined in a prior loop in the same data step. In this example, I want a1 = 1 where _n_=1, a1 = 4 when _n_=2.

Does that help? My example was an attempt to simplify my current program. When i run this code, I get the warning "...hs not resolved." and error: "data step component object failure". Message was edited by: AndyC
deleted_user
Not applicable
The macro variable 'hs' will be resolved before the symput is executed, so this won't work.

You could accomplish the intended result (*) by putting a1_1 a2_1 a3_1 into a data step array (say MYARRAY), and then you'd have something like:

a1 = myarray(_n_);

(*) But I'm not convinced I understand what you are really trying to accomplish.
deleted_user
Not applicable
%macro symps;

data test2 ( keep = a1 );
set test;
array myarray(3) a1_1 a2_1 a3_1;
a = myarray(_n_);

run;

%mend symps;
Thanks that works in my example. Hope it will work in the context of my larger program. Andy
sbb
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10
Suggest you exercise the DATA step - recommend adding the line:

PUTLOG _ALL_;

so you can see the SAS variables at any given point in the DATA step portion of the program.

Also, your SAS log will likely have some tell-tale diagnostic NOTE, WARNING or ERROR messages for you to review and possibly debug, for example - given your code, I expect you will have a note:

NOTE: VARIABLE A IS UNINITIALIZED

and you will see from the PUTLOG that the named variable does not have an assigned value -- because of your assignment line.

And given that you likely want an observation for each A1 value, you will need to code a DO / END loop to bump through the array, and issue an OUTPUT statement within the DO loop.

Scott Barry
SBBWorks, Inc.

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