From: Jay on
On May 26, 5:52 pm, Ya <huang8...(a)gmail.com> wrote:
> On May 26, 1:40 pm, Jay <jingsi....(a)gmail.com> wrote:
>
>
>
> > On May 26, 4:26 pm, Paige Miller <paige.mil...(a)kodak.com> wrote:
>
> > > On May 26, 4:09 pm, Jay <jingsi....(a)gmail.com> wrote:
>
> > > > Suppose I have a dataset like
> > > > VAR VAL
> > > > C2 2
> > > > B9 3
> > > > D4 4
> > > > ... ...
> > > > How do I create macro variables C2, B9, D4 etc and assign them the
> > > > corresponding values?
>
> > > > many thanks
>
> > > CALL SYMPUT function
>
> > > --
> > > Paige MIller
> > > paige\dot\miller \at\ kodak\dot\com
>
> > something like
>
> > data _null_;
> > set something;
> > call symput(%var,&val);
> > run;
>
> > i want the system to read a observation, assign the value of var to a
> > macro variable of that name and assign val as its value
>
> > thanks again- Hide quoted text -
>
> > - Show quoted text -
>
> data xx;
> input VAR $ VAL;
> cards;
> C2 2
> B9 3
> D4 4
> ;
>
> proc sql noprint;
> select resolve('%let '||trim(var)||'='||trim(put(val,best.-l))||';')
> into :dummy separated by ' '
> from xx
> ;
>
> %put _user_;
>
> GLOBAL D4 4
> GLOBAL B9 3
> GLOBAL DUMMY
> GLOBAL C2 2
>
> HTH
>
> Ya

Thank you. Now I have the macro variables C2,B9,D4,etc. with values
2,3,4
I have another table such as

C2 B9 D4
_______________
1000 2000 3000
4000 5000 6000

And I want to do a substring of each column based on the value of its
global variables.Thus the table will end up looking like

C2 B9 D4
_______________
10 200 3000
40 500 6000

I am able to create an array for each observation. I can get the
column names but I don't know how to substring the values from the
macros

array vars C2 B9 D4 ;
do i = 1 to dim(vars);

%LET tmp=vname(vars(i));
vars(i)= substr(vars(i),1,&&tmp);

end;

I am unable to get the desired value for macro variable with &&tmp,
please help, thank you.



From: Tom Abernathy on
Why did you put them into macro variable when you need them in dataset
variables?

Anyway if we assume you have the values delimited with spaces instead
of commas then your data step code is easier.

%let varlist=C2 B9 D4;
%let values=2 3 4;
%let nvars=3;

array _trim _temporary_ (&nvars) (&values) ;
array vars &varlist;
do i=1 to &nvars;
vars(i)=substr(vars(i),1,_trim(i));
end;


On May 27, 6:15 pm, Jay <jingsi....(a)gmail.com> wrote:
> On May 26, 5:52 pm, Ya <huang8...(a)gmail.com> wrote:
>
>
>
>
>
> > On May 26, 1:40 pm, Jay <jingsi....(a)gmail.com> wrote:
>
> > > On May 26, 4:26 pm, Paige Miller <paige.mil...(a)kodak.com> wrote:
>
> > > > On May 26, 4:09 pm, Jay <jingsi....(a)gmail.com> wrote:
>
> > > > > Suppose I have a dataset like
> > > > > VAR     VAL
> > > > > C2        2
> > > > > B9        3
> > > > > D4        4
> > > > > ...         ...
> > > > > How do I create macro variables C2, B9, D4 etc and assign them the
> > > > > corresponding values?
>
> > > > > many thanks
>
> > > > CALL SYMPUT function
>
> > > > --
> > > > Paige MIller
> > > > paige\dot\miller \at\ kodak\dot\com
>
> > > something like
>
> > > data _null_;
> > >         set something;
> > >         call symput(%var,&val);
> > > run;
>
> > > i want the system to read a observation, assign the value of var to a
> > > macro variable of that name and assign val as its value
>
> > > thanks again- Hide quoted text -
>
> > > - Show quoted text -
>
> > data xx;
> > input VAR $ VAL;
> > cards;
> > C2        2
> > B9        3
> > D4        4
> > ;
>
> > proc sql noprint;
> > select resolve('%let '||trim(var)||'='||trim(put(val,best.-l))||';')
> >  into :dummy separated by ' '
> > from xx
> > ;
>
> > %put _user_;
>
> > GLOBAL D4 4
> > GLOBAL B9 3
> > GLOBAL DUMMY
> > GLOBAL C2 2
>
> > HTH
>
> > Ya
>
> Thank you. Now I have the macro variables C2,B9,D4,etc. with values
> 2,3,4
> I have another table such as
>
>    C2   B9   D4
> _______________
>  1000 2000 3000
>  4000 5000 6000
>
> And I want to do a substring of each column based on the value of its
> global variables.Thus the table will end up looking like
>
>    C2   B9   D4
> _______________
>     10 200 3000
>     40 500 6000
>
> I am able to create an array for each observation. I can get the
> column names but I don't know how to substring the values from the
> macros
>
> array vars C2 B9 D4 ;
>                 do i = 1 to dim(vars);
>
>                        %LET tmp=vname(vars(i));
>                         vars(i)= substr(vars(i),1,&&tmp);
>
>                 end;
>
> I am unable to get the desired value for macro variable with &&tmp,
> please help, thank you.

From: shiva on
Hi Jay,

Try this ....Hope this helps...

data xx;
input VAR $ VAL;
cards;
C2 2
B9 3
D4 4
;
run;

data _null_ ;
set xx;
call symput(trim(left(VAR)), trim(LEFT(VAL)));
run;
%put &c2;

Thanks,
shiva