Discussion:
How to use Call Symputx in Data Step
(too old to reply)
l***@gmail.com
2018-06-06 01:55:53 UTC
Permalink
I have a data set "A" as follow (n is the number of element in Name_ROW)
Id n Name_Row
1 3 Jack|Albert|Rice
2 2 Geroge|Rodman
--
I want to transform into "B" as

ID Name
1 Jack
1 Albert
1 Rice
2 George
2 Rodman
--------------

Data B;
Set A;
Retain ID N Name_Row;
Call Symputx("n",n);
%do i=1 %to &n.;
Name_List=scan(Name_Row,&i.,"|");
output;
%end;
run;
---------------------------
It seems Call Symputx("n",n); fails. How can I fix the problem?
Barry Schwarz
2018-06-06 06:00:50 UTC
Permalink
Post by l***@gmail.com
I have a data set "A" as follow (n is the number of element in Name_ROW)
Id n Name_Row
1 3 Jack|Albert|Rice
2 2 Geroge|Rodman
--
Many usenet readers treat this sequence as the end of the message
body. If you need a segment separator, use underscores or equal
signs.
Post by l***@gmail.com
I want to transform into "B" as
ID Name
1 Jack
1 Albert
1 Rice
2 George
2 Rodman
--------------
Data B;
Set A;
Retain ID N Name_Row;
Call Symputx("n",n);
%do i=1 %to &n.;
Name_List=scan(Name_Row,&i.,"|");
output;
%end;
run;
---------------------------
It seems Call Symputx("n",n); fails. How can I fix the problem?
If you look at the description of the symput functions in the macro
reference, you will see a section that explains why the value of %n is
not available within the same data step that called symputx.

In this case, a macro is completely unnecessary. You are not
interested in generating a data step with n calls to scan. You are
interested in executing exactly n call to scan for each observation
where n may be different in each observation.

DATA B Keep = id name
SET A
DO i = 1 TO n
name = SCAN(name_row, i, "|")
OUTPUT
END
RUN
--
Remove del for email
Loading...