From: CC on 20 Mar 2010 20:48 Hi I tried to prefix some variables and found someone wrote a solution already. But there is one part of the codes that I am not so sure. Could anyone answer it for me? Thanks data _null_; set sashelp.class (obs=1); array nu _numeric_; length renl $200; renl=''; do over nu; renl=trim(renl)||' '||vname(nu)||'=P_'||left(vname(nu)); end; call symput('renl',renl); run; My question is what is the meaning of ||' '|| in the renl=trim(renl)||' '||vname(nu)||'=P_'||left(vname(nu)); Especially for the first ||' '|| --- What is that for? Also, I was wondering that where can I find the information regarding the use of ||' '|| in the SAS support. I thought we have to use ||' '|| this kind of sign when using call execute function or something. Not so sure why and how we use this in the data step. Thank you in advance!
From: Tom Abernathy on 20 Mar 2010 21:53 ' ' is just a blank space that is used to separated the words in the generated string. || is the concatenation operator. On Mar 20, 8:48 pm, CC <chchanghe...(a)gmail.com> wrote: > Hi I tried to prefix some variables and found someone wrote a > solution already. But there is one part of the codes that I am not so > sure. Could anyone answer it for me? Thanks > > data _null_; > set sashelp.class (obs=1); > array nu _numeric_; > length renl $200; > renl=''; > do over nu; > renl=trim(renl)||' '||vname(nu)||'=P_'||left(vname(nu)); > end; > call symput('renl',renl); > run; > > My question is what is the meaning of ||' '|| in the > renl=trim(renl)||' '||vname(nu)||'=P_'||left(vname(nu)); > > Especially for the first ||' '|| --- What is that for? > Also, I was wondering that where can I find the information regarding > the use of ||' '|| in the SAS support. I thought we have to use > ||' '|| this kind of sign when using call execute function or > something. Not so sure why and how we use this in the data step. > > Thank you in advance!
From: CC on 21 Mar 2010 22:33 Thanks Tom! I have one more stupid question. As we are trying to create two variables. Should we write-- renl=trim(renl); vname(nu)||'=P_'||left(vname(nu)); I am not sure if we can just use "" as a blank space to create two variables? Could you clarify it for me? Thanks a lot! On Mar 21, 9:53 am, Tom Abernathy <tom.aberna...(a)gmail.com> wrote: > ' ' is just a blank space that is used to separated the words in the > generated string. > || is the concatenation operator. > > On Mar 20, 8:48 pm, CC <chchanghe...(a)gmail.com> wrote: > > > Hi I tried to prefix some variables and found someone wrote a > > solution already. But there is one part of the codes that I am not so > > sure. Could anyone answer it for me? Thanks > > > data _null_; > > set sashelp.class (obs=1); > > array nu _numeric_; > > length renl $200; > > renl=''; > > do over nu; > > renl=trim(renl)||' '||vname(nu)||'=P_'||left(vname(nu)); > > end; > > call symput('renl',renl); > > run; > > > My question is what is the meaning of ||' '|| in the > > renl=trim(renl)||' '||vname(nu)||'=P_'||left(vname(nu)); > > > Especially for the first ||' '|| --- What is that for? > > Also, I was wondering that where can I find the information regarding > > the use of ||' '|| in the SAS support. I thought we have to use > > ||' '|| this kind of sign when using call execute function or > > something. Not so sure why and how we use this in the data step. > > > Thank you in advance!
From: Barry Schwarz on 22 Mar 2010 01:09 On Sun, 21 Mar 2010 19:33:41 -0700 (PDT), CC <chchanghenry(a)gmail.com> wrote: >Thanks Tom! I have one more stupid question. > >As we are trying to create two variables. Should we write-- Are we? You will have to ask the "someone" who wrote the code you quoted. As it stands, it obviously creates in the single variable renl a single long character value which happens to start with a leading blank (courtesy of trim) and followed by dim(nu) substrings, each consisting of a blank followed by the name of a variable followed by =P_ followed by the same variable name left justified. (I wasn't aware that variable names could start with a blank so I'm confused about the use of left here.) Based on the name renl, I would expect this string is eventually going to find its way into a rename data set option, something like rename= x=P_x y=P_y ... >renl=trim(renl); >vname(nu)||'=P_'||left(vname(nu)); > >I am not sure if we can just use "" as a blank space to create two >variables? Could you clarify it for me? Not like this you can't. The only variable (not counting the loop variable nu) being assigned to is renl so I don't know why you are assuming more than one. > >On Mar 21, 9:53�am, Tom Abernathy <tom.aberna...(a)gmail.com> wrote: >> ' ' is just a blank space that is used to separated the words in the >> generated string. >> || is the concatenation operator. >> >> On Mar 20, 8:48�pm, CC <chchanghe...(a)gmail.com> wrote: >> >> > Hi �I tried to prefix some variables and found someone wrote a >> > solution already. �But there is one part of the codes that I am not so >> > sure. �Could anyone answer it for me? �Thanks >> >> > data _null_; >> > �set sashelp.class (obs=1); >> > array nu _numeric_; >> > length renl $200; >> > renl=''; >> > do over nu; >> > renl=trim(renl)||' '||vname(nu)||'=P_'||left(vname(nu)); >> > end; >> > call symput('renl',renl); >> > run; >> >> > My question is what is the meaning of ||' '|| in the >> > renl=trim(renl)||' '||vname(nu)||'=P_'||left(vname(nu)); >> >> > Especially for the first �||' '|| --- �What is that for? >> > Also, I was wondering that where can I find the information regarding >> > the use of �||' '|| in the SAS support. � I thought we have to use >> > ||' '|| �this kind of sign when using call execute function or >> > something. � Not so sure why and how we use this in the data step. >> >> > Thank you in advance! -- Remove del for email
From: Tom Abernathy on 22 Mar 2010 08:51
Not sure what you mean by creating variables. The original code was generating a RENAME command to change the name of existing variables. Perhaps you mean that instead of renaming the variables you would like to create new variables? In that case you could generate a series of assignment statements instead of the RENAME statement. As these will be statements instead of just clauses for a single statement you will need to include a semi- colon in the generated code. I find that for this type of code generation work it is much easier to write the code to a file and then use %INC to run it. It is easer to understand and debug than generating code into string variables or macro variables. You can read in the generated code and look at it before you submit it to make sure you have generated what you expected. filename rename temp; filename newvars temp; data _null_; if 0 then set sashelp.class; array nu _numeric_; * Write RENAME statement ; file rename ; put 'RENAME ' @; do over nu; vname=vname(nu); put vname '=' 'P_' vname @; end; put ';' ; * Write assignment statements ; fiel newvars; do over nu; vname=vname(nu); put 'P_' vname '=' vname ';'; end; run; data rename; set sashelp.class; %inc rename / source2 ; run; data newvars; set sashelp.class; %inc newvars / source2 ; run; On Mar 21, 10:33 pm, CC <chchanghe...(a)gmail.com> wrote: > Thanks Tom! I have one more stupid question. > > As we are trying to create two variables. Should we write-- > renl=trim(renl); > vname(nu)||'=P_'||left(vname(nu)); > > I am not sure if we can just use "" as a blank space to create two > variables? Could you clarify it for me? > Thanks a lot! > > On Mar 21, 9:53 am, Tom Abernathy <tom.aberna...(a)gmail.com> wrote: > > > > > ' ' is just a blank space that is used to separated the words in the > > generated string. > > || is the concatenation operator. > > > On Mar 20, 8:48 pm, CC <chchanghe...(a)gmail.com> wrote: > > > > Hi I tried to prefix some variables and found someone wrote a > > > solution already. But there is one part of the codes that I am not so > > > sure. Could anyone answer it for me? Thanks > > > > data _null_; > > > set sashelp.class (obs=1); > > > array nu _numeric_; > > > length renl $200; > > > renl=''; > > > do over nu; > > > renl=trim(renl)||' '||vname(nu)||'=P_'||left(vname(nu)); > > > end; > > > call symput('renl',renl); > > > run; > > > > My question is what is the meaning of ||' '|| in the > > > renl=trim(renl)||' '||vname(nu)||'=P_'||left(vname(nu)); > > > > Especially for the first ||' '|| --- What is that for? > > > Also, I was wondering that where can I find the information regarding > > > the use of ||' '|| in the SAS support. I thought we have to use > > > ||' '|| this kind of sign when using call execute function or > > > something. Not so sure why and how we use this in the data step. > > > > Thank you in advance!- Hide quoted text - > > - Show quoted text - |