BookmarkSubscribeRSS Feed
lchristensen
Obsidian | Level 7

SAS V9.4 on Windows 10.

I will be performing some testing of new storage behind a Brocade switch. The testing will require enabling and disabling specific ports and changing the speed for some ports.

I have written a macro to build files for each test. They are being written to my user/me/ folder. I want to have the main program use a folder in the filename statement and then have each file I am building be a file within that Windows folder.

I have a second issue. I have a series of nested loops. The outer most loop is   'do type = 'A','N';  the inner most within each creates a file that has way too many lines in it. Most will have 8-10 records, the inner most within the TYPE loop however is getting hundreds. Perhaps  it is getting every record created and placed into the other files.

 

So main question is: how do I set the file names to be in the folder  the main program uses as the location of the filename?

2nd question is can you see why the inner most loop is getting an excessive number of records?

6 REPLIES 6
ballardw
Super User

Code like this is using a Fileref as the argument of the File statement. That means somewhere prior to this code executing There should be a Filename statement that creates the Fileref.

if z_speed = '0' and Stg_speed = '0' 	then file AJG;

The filename might look like

Filename AJG "<folder>\something.txt";

If you have an existing Fileref as described perhaps something like:

data _null_;
   length path fname $ 200;  /*<= long enough to hold maximum expected path/filename*/
   /* check if the "existing" fileref is actually defined*/
   /* obviously the CFG_SW example could be a parameter to the
      macro change the base folder
   */
   rc=fileref("CFG_SW");
   if (rc=0) then
   /* found fileref so create filename statements*/
   do;
      /*get the path to the fileref */
      path=pathname("CFG_SW",F);
      do filext = 'AJL','AJR','AJX';/* list all of the file arguments */
         /* build the desired file name to use */
         fname = cats(path,'\',filext,'.txt');
         /* I would test this code with PUT statments before 
            actually executing the Filename 
         */
         put fname=;
         /* assign the fileref */
         rc= filename(filext,fname )  ;
         /* if the filename doesn't assign properly get message*/
         if rc ne 0 then do;
           txt= sysmsg();
          put fname=  ' Message: ' txt;
 
         end;
      end;
   end;
run;

Personally I would have this execute before the main macro to debug any issues with specific lists.

If you don't want to manually list a bunch of the filerefs to use place them in a dataset and use that data set to get the values instead of the Filext loop.

 

Your second issue means you may want to show what you are getting and examples of the "too many lines".

Put should only write to the most recently assigned FILE destination. Since you don't show where any of the Filerefs are assigned for your code I can't tell what might be going on.

 

lchristensen
Obsidian | Level 7

Data Work.Gen_JCL;
filename CFG_SW 'z:\mainframe\GPSE\ITPro32gb\SW_CMDS';
%FICON_SW(CHB_PAIR='1A');
run;

 

The data step invoking the macro has a filename statement. It stops at the folder SW_CMDS. What I would like is for the macro to then build each file within the folder (SW_CMDS) based on the test.

 

If running on z/OS I'm fairly certain that works when the filename points to a partitioned dataset with the macro doing a FILE (member-name) for the member.

Tom
Super User Tom
Super User

You do realize that the data step you posted

Data Work.Gen_JCL;
filename CFG_SW 'z:\mainframe\GPSE\ITPro32gb\SW_CMDS';
%FICON_SW(CHB_PAIR='1A');
run;

makes NO sense what so ever.

The macro you showed by for is generating a data step already.  So it is as if you want this code:

Data Work.Gen_JCL;
filename CFG_SW 'z:\mainframe\GPSE\ITPro32gb\SW_CMDS';
Data  Work.BLD_Switch_commands;
...
run;

Which is the equivalent of running

Data Work.Gen_JCL;
run;
filename CFG_SW 'z:\mainframe\GPSE\ITPro32gb\SW_CMDS';
Data  Work.BLD_Switch_commands;
...
run;

Not sure why you want to create GEN_JCL dataset with one observation and zero variables.

Oligolas
Barite | Level 11

Hi,

You're looping through do z_speed = '0','32','16','08'; but only define a file for z_speed = '0' 

  • in which file should be written for the remaining values '32','16','08' ?

 

do z_speed  =  '0','32','16','08';                 /* z15 speed (0=autonegotiate)         -2 */

 

 

 

                     if z_speed = '0' and Stg_speed = '0'   then file AJG;
                     if z_speed = '0' and Stg_speed = '32'  then file AJM;
                     if z_speed = '0' and Stg_speed = '16'  then file AJS;
                     if z_speed = '0' and Stg_speed = '08'  then file AJY;

                     if z_speed = '0' and Stg_speed = '0'   then put @  001   "***  file AJG ***"  ;
                     if z_speed = '0' and Stg_speed = '32'  then put @  001   "***  file AJM ***"  ;
                     if z_speed = '0' and Stg_speed = '16'  then put @  001   "***  file AJS ***"  ;
                     if z_speed = '0' and Stg_speed = '08'  then put @  001   "***  file AJY ***"  ;

 

 

________________________

- Cheers -

lchristensen
Obsidian | Level 7

I am not yet testing the other z_speeds and was thinking that since there's no matching if to assign a file then there'd be no output for those other speeds but I guess it used the last file statement. Easy enough to work around with something like:

     if z_speed ne '0' then delete;

 

Thank you

lchristensen
Obsidian | Level 7

Correction:

if z_speed NE '0' then leave;

 

Works as desired for that. Thank you.

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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
  • 6 replies
  • 497 views
  • 0 likes
  • 4 in conversation