The SAS Output Delivery System and reporting techniques

creating a plot graph for each unique objectname

Posts: 0

creating a plot graph for each unique objectname

Hey all
I have a dataset with statistics on which I want to create
plot graph for each unique objectname
There are a lot of unique objectname's like more than 100 so I cannot
plot them all in the same graph
I managed to create a list of unique objectname values using proc sql select distinct to create a second dataset containing only unique values, but now I cant find a way to loop through these unique values and call the macro that will create the plot graph ..

I tried to do it using a data step, knowing that it would most probably doesnt work :

data _null_;
set work.uniqueObjects;

The dataset containing the Unique objectsnames has only one variable named ObjectName

Thanks for your always great help
Posts: 0

Re: creating a plot graph for each unique objectname

Oh Gosh, you are so close.

So you have a (tested) macro that will take an object name and build a plot, and now you just want to call that for each record in a table... have I got that right?

You could use a Call function called Call Execute() but I became disenchanted with that when it had a memory leak problem on Windows in Version 8. I favour a solution I shall call the Kent solution because in a discussion between He and Me, he gratuitously suggested my alternative approach was better because it was conservative of memory and allowed debugging that throwing commands into memory did not. Here is some code, just a couple of lines to add to your program.

FileName CODEINCL Temp;

Data _NULL_;
/* File CODEINCL; */
Put '%Create( ' OBJECTNAME ');';

%Include CODEINCL;

FileName CODEINCL Clear;

In the data step, the file reference is commented out so that the first time you run it you get all the commands written to the LOG. This allows you to verify the command is well formed. You can also be conservative and run it first time with an ( Obs = 5) option on the Set table so that you don't write many repetitive lines in the log. Don't forget the command must be complete; a common oversight is that there need to be two semi colons around the end of the Put statement. One is inside to write the command to the file, one outside to complete the SAS Put command.

Then when you remove comments from the FILE line, the file is written to and will be submitted in the %include call. Using a Temp reference for the file means SAS will ask the OS to manage the file creation. This means you don't need to think about where you might put it. It also works on all operating systems, so you needn't think about paths, permissions, blocking, deleting old files or anything else when you write the code.

BIG TRAP: Do NOT N O T NOT use double quotes at the Put statement. SAS will attempt to resolve the macro reference, and you don't want that to happen until the command is properly formed in the command file. It's a common problem, and can cause instability in your SAS session with some macros, so I suggest you also save the code before you submit it.

Kind regards

Posts: 0

Re: creating a plot graph for each unique objectname

Thank you so much, it works perfectly
But im surprised to have to use a workaround using a tempfile
just to do this simple looping through variable values

well it works thats what counts
Posts: 0

Re: creating a plot graph for each unique objectname

You need to look at the context of the commands. The macro calls will present code to the SAS Supervisor, which will then attempt to compile and execute it.

The problem is that you don't want it to compile and execute until it has done everything you wanted it to do with your source data, that is: building the SAS commands to execute your macro for each value in the source table.

Kind regards

Super Contributor
Posts: 260

Re: creating a plot graph for each unique objectname

Maybe some silly solution :
did you try to insert a BY statement in your graphic procedure ?
That would loop without effort (except the one of sorting or indexing the dataset before plotting) throught all values of ObjectName !

Ask a Question
Discussion stats
  • 4 replies
  • 2 in conversation