BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
jamal01
Fluorite | Level 6

Hello,

 

I have this macro variable:

jamal01_0-1669825541363.png

and I am trying to extract "ITERATIONS=10", is there any way to do that?

 

Macro is from proc optmodel

 

Please let me know if you need any other info.

1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26

@jamal01 wrote:

The pair that begins with ITERATIONS


%let mvar=GLOBAL _OROPTMODEL_ STATUS=OK ALGORITHM=IP SOLUTION_STATUS=OPTIMAL OBJECTIVE=4482560894.6 PRIMAL_INFEASIBILITY=2.495295E-16 DUAL_INFEASIBILITY=9.21096E-19 BOUND_INFEASIBILITY=0 DUALITY_GAP=1.252394E-11 COMPLEMENTARITY=0 ITERATIONS=10 PRESOLVE_TIME=0.00 SOLUTION_TIME=0.02;

data _null_;
    where=find("&mvar",'ITERATIONS');
    want=scan(substr("&mvar",where),2,'= ');
    call symputx('want',want);
run;
%put &=want;
--
Paige Miller

View solution in original post

8 REPLIES 8
PaigeMiller
Diamond | Level 26

We generally can't work from screen captures. Please, in the future, provide data as text.

 

What do you mean by you want to extract "ITERATIONS=10" from the macro variable? If you already know you want ITERATIONS=10, there's no need to extract it. Do you mean something else? Do you mean you want to extract the n-th data pair? Do you mean you want the data pair that begins with ITERATIONS? 

--
Paige Miller
jamal01
Fluorite | Level 6

Sorry, here is the data: 

GLOBAL _OROPTMODEL_ STATUS=OK ALGORITHM=IP SOLUTION_STATUS=OPTIMAL OBJECTIVE=4482560894.6 PRIMAL_INFEASIBILITY=2.495295E-16
DUAL_INFEASIBILITY=9.21096E-19 BOUND_INFEASIBILITY=0 DUALITY_GAP=1.252394E-11 COMPLEMENTARITY=0 ITERATIONS=10 PRESOLVE_TIME=0.00
SOLUTION_TIME=0.02

 

Right, I can see that ITERATIONS=10 in the macro, but I was trying to write a small put statement and display something along the lines of "The number of iterations is 10".

 

PaigeMiller
Diamond | Level 26

So, are you looking for:

 

  • the N-th data pair
  • a data pair that ends with 10
  • a data pair that begins with ITERATIONS
  • something else
--
Paige Miller
jamal01
Fluorite | Level 6

The pair that begins with ITERATIONS

PaigeMiller
Diamond | Level 26

@jamal01 wrote:

The pair that begins with ITERATIONS


%let mvar=GLOBAL _OROPTMODEL_ STATUS=OK ALGORITHM=IP SOLUTION_STATUS=OPTIMAL OBJECTIVE=4482560894.6 PRIMAL_INFEASIBILITY=2.495295E-16 DUAL_INFEASIBILITY=9.21096E-19 BOUND_INFEASIBILITY=0 DUALITY_GAP=1.252394E-11 COMPLEMENTARITY=0 ITERATIONS=10 PRESOLVE_TIME=0.00 SOLUTION_TIME=0.02;

data _null_;
    where=find("&mvar",'ITERATIONS');
    want=scan(substr("&mvar",where),2,'= ');
    call symputx('want',want);
run;
%put &=want;
--
Paige Miller
jamal01
Fluorite | Level 6

This is what my log is looking like when I try to run it: 

1                                                          The SAS System                         18:06 Wednesday, November 30, 2022

1          ;*';*";*/;quit;run;
2          OPTIONS PAGENO=MIN;
3          %LET _CLIENTTASKLABEL='Program';
           _
           180
ERROR 180-322: Statement is not valid or it is used out of proper order.

4          %LET _CLIENTPROCESSFLOWNAME='Standalone Not In Project';
           _
           180
ERROR 180-322: Statement is not valid or it is used out of proper order.

5          %LET _CLIENTPROJECTPATH='';
           _
           180
ERROR 180-322: Statement is not valid or it is used out of proper order.

6          %LET _CLIENTPROJECTPATHHOST='';
           _
           180
ERROR 180-322: Statement is not valid or it is used out of proper order.

7          %LET _CLIENTPROJECTNAME='';
           _
           180
ERROR 180-322: Statement is not valid or it is used out of proper order.

8          %LET _SASPROGRAMFILE='';
           _
           180
ERROR 180-322: Statement is not valid or it is used out of proper order.

9          %LET _SASPROGRAMFILEHOST='';
           _
           180
ERROR 180-322: Statement is not valid or it is used out of proper order.

10         
11         ODS _ALL_ CLOSE;
12         OPTIONS DEV=SVG;
13         GOPTIONS XPIXELS=0 YPIXELS=0;
14         %macro HTML5AccessibleGraphSupported;
           _
           180
ERROR 180-322: Statement is not valid or it is used out of proper order.

15             %if %_SAS_VERCOMP_FV(9,4,4, 0,0,0) >= 0 %then ACCESSIBLE_GRAPH;
               _
               180
ERROR 180-322: Statement is not valid or it is used out of proper order.

16         %mend;
           _
           180
ERROR 180-322: Statement is not valid or it is used out of proper order.

17         FILENAME EGHTML TEMP;
18         ODS HTML5(ID=EGHTML) FILE=EGHTML
2                                                          The SAS System                         18:06 Wednesday, November 30, 2022

19             OPTIONS(BITMAP_MODE='INLINE')
20             %HTML5AccessibleGraphSupported
               _
               22
               200
ERROR 22-322: Syntax error, expecting one of the following: ;, ACCESSIBLE_GRAPH, ANCHOR, ARCHIVE, ATTRIBUTES, BASE, BODY, 
              BOX_SIZING, CHARSET, CLOSE, CODE, CODEBASE, CONTENTS, CSS, CSSSTYLE, DOM, DPI, ENCODING, EVENT, FILE, FRAME, 
              GFOOTNOTE, GPATH, GTITLE, HEADTEXT, IMAGE_DPI, METATEXT, NEWFILE, NOACCESSIBLE_GRAPH, NOGFOOTNOTE, NOGTITLE, OPTIONS, 
              PACKAGE, PAGE, PARAMETERS, PATH, RECORD_SEPARATOR, SGE, STYLE, STYLESHEET, TEXT, TRANTAB.  

ERROR 200-322: The symbol is not recognized and will be ignored.

21             ENCODING='utf-8'
22             STYLE=HtmlBlue
23             NOGTITLE
24             NOGFOOTNOTE
25             GPATH=&sasworklocation
                     _
                     22
                     200
ERROR 22-322: Syntax error, expecting one of the following: a name, a quoted string.  
ERROR 200-322: The symbol is not recognized and will be ignored.
26         ;
27         
28         %let mvar=GLOBAL _OROPTMODEL_ STATUS=OK ALGORITHM=IP SOLUTION_STATUS=OPTIMAL OBJECTIVE=4482560894.6
           _
           180
28       ! PRIMAL_INFEASIBILITY=2.495295E-16 DUAL_INFEASIBILITY=9.21096E-19 BOUND_INFEASIBILITY=0 DUALITY_GAP=1.252394E-11
28       ! COMPLEMENTARITY=0 ITERATIONS=10 PRESOLVE_TIME=0.00 SOLUTION_TIME=0.02;
ERROR 180-322: Statement is not valid or it is used out of proper order.

29         
30         data _null_;
31             where=find("&mvar",'ITERATIONS');
32             want=scan(substr("&mvar",where),2,'= ');
33             call symputx('want',want);
34         run;
ERROR: Invalid second argument to function SUBSTR at line 32 column 15.
where=0 want=  _ERROR_=1 _N_=1
35         %put &=want;
           _
           180
ERROR 180-322: Statement is not valid or it is used out of proper order.

36         
37         %LET _CLIENTTASKLABEL=;
           _
           180
ERROR 180-322: Statement is not valid or it is used out of proper order.

38         %LET _CLIENTPROCESSFLOWNAME=;
           _
           180
ERROR 180-322: Statement is not valid or it is used out of proper order.

39         %LET _CLIENTPROJECTPATH=;
           _
           180
3                                                          The SAS System                         18:06 Wednesday, November 30, 2022

ERROR 180-322: Statement is not valid or it is used out of proper order.

40         %LET _CLIENTPROJECTPATHHOST=;
           _
           180
ERROR 180-322: Statement is not valid or it is used out of proper order.

41         %LET _CLIENTPROJECTNAME=;
           _
           180
ERROR 180-322: Statement is not valid or it is used out of proper order.

42         %LET _SASPROGRAMFILE=;
           _
           180
ERROR 180-322: Statement is not valid or it is used out of proper order.

43         %LET _SASPROGRAMFILEHOST=;
           _
           180
ERROR 180-322: Statement is not valid or it is used out of proper order.

44         
45         ;*';*";*/;quit;run;
46         ODS _ALL_ CLOSE;
47         
48         
49         QUIT; RUN;
50         

Any idea why this might be happening?

PaigeMiller
Diamond | Level 26

Save your data sets, exit from SAS, re-launch SAS and try it again

--
Paige Miller
Tom
Super User Tom
Super User

So if you have this string 

GLOBAL _OROPTMODEL_ STATUS=OK ALGORITHM=IP SOLUTION_STATUS=OPTIMAL OBJECTIVE=4482560894.6 PRIMAL_INFEASIBILITY=2.495295E-16
DUAL_INFEASIBILITY=9.21096E-19 BOUND_INFEASIBILITY=0 DUALITY_GAP=1.252394E-11 COMPLEMENTARITY=0 ITERATIONS=10 PRESOLVE_TIME=0.00
SOLUTION_TIME=0.02

It looks like is a series of name=value pairs delimited by spaces.

%let string=
GLOBAL _OROPTMODEL_ STATUS=OK ALGORITHM=IP SOLUTION_STATUS=OPTIMAL OBJECTIVE=4482560894.6 PRIMAL_INFEASIBILITY=2.495295E-16
DUAL_INFEASIBILITY=9.21096E-19 BOUND_INFEASIBILITY=0 DUALITY_GAP=1.252394E-11 COMPLEMENTARITY=0 ITERATIONS=10 PRESOLVE_TIME=0.00
SOLUTION_TIME=0.02
;

data want;
  length index 8 name $32 value $32;
  length string $32767 ;
  string=symget('string');
  do index=1 to countw(string,' ');
     name = scan(scan(string,index,' '),1,'=');
     value = scan(scan(string,index,' '),2,'=');
     output;
  end;
  drop string;
run;

Result:

Obs    index    name                    value

  1       1     GLOBAL
  2       2     _OROPTMODEL_
  3       3     STATUS                  OK
  4       4     ALGORITHM               IP
  5       5     SOLUTION_STATUS         OPTIMAL
  6       6     OBJECTIVE               4482560894.6
  7       7     PRIMAL_INFEASIBILITY    2.495295E-16
  8       8     DUAL_INFEASIBILITY      9.21096E-19
  9       9     BOUND_INFEASIBILITY     0
 10      10     DUALITY_GAP             1.252394E-11
 11      11     COMPLEMENTARITY         0
 12      12     ITERATIONS              10
 13      13     PRESOLVE_TIME           0.00
 14      14     SOLUTION_TIME           0.02

Looks like the beginning of the string does not follow the rules of the rest of the string.

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 8 replies
  • 1007 views
  • 2 likes
  • 3 in conversation