BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
capam
Pyrite | Level 9

I'm attempting to access a variable in have for calling a macro from a do loop. When I try the following code I get errors:

 

ERROR: The DIM, LBOUND, and HBOUND functions require an array name for the first argument.

ERROR 68-185: The function Var_in_have is unknown, or cannot be accessed.

data have;
	call execute('proc sql;');

	do i=1 to dim(Var_in_have) while (Var_in_have(i) ne .);
		call execute(cats('%nrstr(%some_macro)(',Var_in_have(i),')'));
	end;

	call execute('quit;');
run;
1 ACCEPTED SOLUTION

Accepted Solutions
Astounding
PROC Star

Yes, you will need the code from the wizard, so you can plug it into a program.  If you are looking to get a separate plot for each combination of values that VEHNO and FAULTNO take on, it sounds like you need this:

 

proc sort data=have;

by VehNo FaultNo;

run;

 

proc plot /* or sgplot or whatever the wizard tells  you to use */ data=have;

by VehNo FaultNo;

*** Add the rest of the code from the wizard;

run;

 

 

View solution in original post

5 REPLIES 5
Reeza
Super User

You don't have a SET statement so you aren't using any data. 

 

Build your string outside of CALL EXECUTE and check what it's generating first. Then pass the string to CALL EXECUTE. 

 

In my experience, you don't usually need the %nrstr() when using CALL EXECUTE unless there's something you need to mask. 



Astounding
PROC Star

There are bright red DANGER signs throughout your post that indicate you should not be doing this.

 

You need to understand SAS language for macro language to be useful.  Macro language does not process your data.  It builds a program by generating working SAS statements.  You are not ready for this yet.  Here are just a few examples.

 

Your message indicates that you think you are using data from the data set HAVE.  You're not.  There is nothing about your program that reads from an existing SAS data set.

 

You use the DIM function to refer to an array named Var_in_have.  There is no such array.  If you did have such an array, it would seem that it should contain names of variables.  The reference to "ne ." would be incorrect for referring to a missing value for the name of a variable.

 

Your intent seems to be to run a macro for every variable.  While that's possible, it's extremely unlikely that the same macro would be useful for both character and numeric variables.

 

You would do better to describe your original data and what you are trying to accomplish.  You could get answers here, possibly very simple answers.  The answers may or may not include macro language (depending on the goal).

capam
Pyrite | Level 9

Hi Astounding,

 

Thanks for your comments. The problem statement has changed since original posting.

 

Problem statement: generate series of line plots from 4 variables.

Source: have is 1 table with the 4 variables of interest:

VehNo is integer

FaultNo is integer

stat is float

date is dt format.

 

Output will be line plots of stat vs date.

 

Typical loop that calls a line plot macro follows:

 

for i = 1:dim(VehNo)

   for j = 1:dim(FaultNo)

        call line_plot_macro(VehNo(i),FaultNo(j))

   end j

end i

 

The macro will access the data. The macro will organize and plot the stats by occurance date from the instances of a specific fault for a specific vehicle.

 

Initially there should be in the neighborhood of 100 plots which will increase as data is collected. 

 

I can probably get the line plot macro by modifying code generated by the line plot wizard.

 

I hope this is clearer.

 

capam

 

Astounding
PROC Star

Yes, you will need the code from the wizard, so you can plug it into a program.  If you are looking to get a separate plot for each combination of values that VEHNO and FAULTNO take on, it sounds like you need this:

 

proc sort data=have;

by VehNo FaultNo;

run;

 

proc plot /* or sgplot or whatever the wizard tells  you to use */ data=have;

by VehNo FaultNo;

*** Add the rest of the code from the wizard;

run;

 

 

ballardw
Super User

You may want to look into a completely different approach the Graph Templat Language let's you do some pretty interesting things and I think it is much more straight forward then what it looks like you are attempting

 

http://support.sas.com/kb/41/367.html

http://support.sas.com/kb/39/099.html

http://support.sas.com/kb/39/092.html

 

All show different groupings of series charts. Go the Results tabl on the page to see the graph, the Full code will have code to generate the graph.

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
  • 1116 views
  • 3 likes
  • 4 in conversation