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

I cannot pass the variable as the source argument in the index function.

 

DATA TEST;
INPUT NAME $20.;
CARDS;
LARS
ARNE
TOM
;
RUN;

PROC SQL;
SELECT STRIP(NAME) INTO :NOM SEPARATED BY " "
FROM TEST;
QUIT;

DATA TEST2;
FORMAT WORD CONT $200.;
DO I=1 TO 3 UNTIL(CONT="");
WORD=SCAN(SYMGET('NOM'),I, " ");
CONT=SCAN(SYMGET('NOM'),I+1, " ");
MACRO_VAR=SYMGET('NOM');
HELP="'" || strip(WORD) || "'";
NOK=INDEX(SYMGET('NOM'), STRIP(HELP));
OK=INDEX(SYMGET('NOM'), 'ARNE');
OUTPUT;
END;
RUN;
1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

Please describe what you are attempting to do. The code runs but I have no idea what the output should be.

 

And your index is likely failing because you have quotes around the value in "HELP" so there isn't a match in the string.

 

And you really don't need to keep calling symget:

DATA TEST2;
   FORMAT WORD CONT $200.;
   DO I=1 TO 3 UNTIL(CONT="");
      WORD=SCAN("&nom.",I, " ");
      CONT=SCAN("&nom.",I+1, " ");
      MACRO_VAR="&nom.";
      HELP="'" || strip(WORD) || "'";
      NOK=INDEX("&nom.",strip(WORD));
      OK=INDEX("&nom.", 'ARNE');
      OUTPUT;
   END;
RUN;

View solution in original post

1 REPLY 1
ballardw
Super User

Please describe what you are attempting to do. The code runs but I have no idea what the output should be.

 

And your index is likely failing because you have quotes around the value in "HELP" so there isn't a match in the string.

 

And you really don't need to keep calling symget:

DATA TEST2;
   FORMAT WORD CONT $200.;
   DO I=1 TO 3 UNTIL(CONT="");
      WORD=SCAN("&nom.",I, " ");
      CONT=SCAN("&nom.",I+1, " ");
      MACRO_VAR="&nom.";
      HELP="'" || strip(WORD) || "'";
      NOK=INDEX("&nom.",strip(WORD));
      OK=INDEX("&nom.", 'ARNE');
      OUTPUT;
   END;
RUN;

Catch up on SAS Innovate 2026

Dive into keynotes, announcements and breakthroughs on demand.

Explore Now →
Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 1 reply
  • 1198 views
  • 0 likes
  • 2 in conversation