f



Re: Read a variable from Right to Left

On Tue, 21 Mar 2006 14:53:59 -0800, Richie <gsingh24@GMAIL.COM> wrote:

>Hi All,
>
>I want help to substring a variable from right to left, for eg: I have
>a SAS data set which has a variable Address like.
>
>Address
>
>114, Mills Rd, Apt 202
>345 Morris Drive, Apt 345
>Chestnut Avenue Apt # 987
>
>Is there a way I can create a variable say Type like
>
>Type
>
>Apt202
>Apt345
>pt#987
>
>Thanks,
>Richie

The simple answer is to provide a negative value for the
second parameter of the scan() function.
data demo ;
  string = '345 Morris Drive, Apt 345' ;
  last_word   = scan( string, -1 ) ;
  second_last = scan( string, -2 ) ;
  put (_all_)(=) ;
run;

The log shows
string=345 Morris Drive, Apt 345 last_word=345 second_last=Apt


See the online doc for optional third parameter which allows
you to specify what punctuation to (dis)allow, like that '#'

Peter
0
3/22/2006 8:47:52 AM
comp.soft-sys.sas 142828 articles. 3 followers. Post Follow

0 Replies
432 Views

Similar Articles

[PageSpeed] 24

Reply:

Similar Artilces:

Re: Read a variable from Right to Left #4
Richie: Try the following. I assume there is a comma before "Apt # 987" in your third address. Output follows the code. data temp; input; Type=scan(_infile_,-1,","); datalines; 114, Mills Rd, Apt 202 345 Morris Drive, Apt 345 Chestnut Avenue, Apt # 987 ; run; proc print; run; ***** Output ***** The SAS System 15:09 Tuesday, March 21, 2006 2 Obs Type 1 Apt 202 2 Apt 345 3 Apt # 987 J S Huang 1-515-557-3987 fax 1-515-557-2422 >>> Richie <gsingh24@GMAIL.COM> 3/21/2006 4:53:59 PM >>> Hi All, I want help to substring a variable from right to left, for eg: I have a SAS data set which has a variable Address like. Address 114, Mills Rd, Apt 202 345 Morris Drive, Apt 345 Chestnut Avenue Apt # 987 Is there a way I can create a variable say Type like Type Apt202 Apt345 pt#987 Thanks, Richie ...

Re: Read a variable from Right to Left #5 1551917
Richie, Are you trying to squeeze everything in the end part to fit into six characters? I am guessing this based on the sample output. If these are all really addresses then you may not always have apartment numbers. Assuming your question is more general, here is a solution. data _null_ ; length string1 $100 type $6 ; infile cards truncover ; input @1 string1 $char100. ; type = substr(compress(string1),length(compress(string1))-5) ; put string1 = type = ; cards ; 114, Mills Rd, Apt 202 345 Morris Drive, Apt 345 Chestnut Avenue Apt # 987 run ; Venky Chakravarthy On Tue, 21 Mar 2006 14:53:59 -0800, Richie <gsingh24@GMAIL.COM> wrote: >Hi All, > >I want help to substring a variable from right to left, for eg: I have >a SAS data set which has a variable Address like. > >Address > >114, Mills Rd, Apt 202 >345 Morris Drive, Apt 345 >Chestnut Avenue Apt # 987 > >Is there a way I can create a variable say Type like > >Type > >Apt202 >Apt345 >pt#987 > >Thanks, >Richie ...

does PHP read left to right or right to left?
I've two functions. currentHeadline looks in $_GET for a variable called 'image' and prints what it finds. showThumbnail takes an image for a parameter and resizes it before sending it to the screen. But when I do this: <?php showThumbnail(currentImage(), 20, 20); ?> showThumbnail is telling me that it is not being given a file name, and currentImage is printing the file name to the screen. How is that possible? What is the right way to do this? lawrence k wrote: > I've two functions. currentHeadline looks in $_GET for a variable > called 'image' and pr...

Re: Reading Excel datetime variable into SAS
Hi Annie, One approach is to add the following expression contained in the sample datastep below into your datastep. data _null_; DateStringFromExcel = '08/01/2008 17:18'; SASDateTime = input(substr(DateStringFromExcel,1,10),mmddyy10.) *86400+input(substr(DateStringFromExcel,12),time.); format SASDateTime datetime19.; put _all_; run; Hope this is helpful. Mark Terjeson Investment Business Intelligence Investment Management & Research Russell Investments 253-439-2367 Russell Global Leaders in Multi-Manager Investing -----Origina...

Re: How to read a period in a variable from a file to SAS dataset
Rune, Your program is working if your dot is transformed into .. dot dot Or you may test internally filename myfile "d:\rune.txt"; data tp34_jn_dok; length Dokumentbeskrivelse $40. ; infile myfile dlm=">>>" pad ; input @"DOKTITTEL:" dokumentbeskrivelse ; if missing(dokumentbeskrivelse) then dokumentbeskrivelse='missing'; run; Now the question rise why to put a single dot (symbol of numeric missing) in place of a text like missing) as i do in my answer? HTH Andre Rune Runnest� a �crit : > /* > This is the file with the fileref MYFILE: > > --------------------------------------- > DOKTITTEL: this is the first record > --------------------------------------- > DOKTITTEL: . > --------------------------------------- > DOKTITTEL: this is the third record > --------------------------------------- > */ > > /* > I want the second record to be '.', not ' '. > How can I obtain that? > > Rune > */ > filename myfile "d:\temp\myfile.txt"; > > data tp34_jn_dok; > length Dokumentbeskrivelse $40. ; > infile myfile dlm=">>>" pad ; > input @"DOKTITTEL:" dokumentbeskrivelse ; > run; > > -- Andr� WIELKI INED (Institut National d'Etudes D�mographiques) Service Informatique 133 Boulevard Davout 75980 Paris Cedex 20 m�l : wielki@ined.fr t�l : 33 (0) 1 56 0...

Re: How to read a period in a variable from a file to SAS dataset #2
On Mon, 28 Jul 2008 02:01:10 -0700, =?ISO-8859-1?Q?Rune_Runnest=F8?= <rune@FASTLANE.NO> wrote: >/* >This is the file with the fileref MYFILE: > >--------------------------------------- >DOKTITTEL: this is the first record >--------------------------------------- >DOKTITTEL: . >--------------------------------------- >DOKTITTEL: this is the third record >--------------------------------------- >*/ > >/* >I want the second record to be '.', not ' '. >How can I obtain that? > >Rune >*/ >filename myfile "d:\temp\myfile.txt"; > >data tp34_jn_dok; > length Dokumentbeskrivelse $40. ; > infile myfile dlm=">>>" pad ; > input @"DOKTITTEL:" dokumentbeskrivelse ; >run; Use the $CHAR informat. ...

Re: Importing Right to left language language from Excel to sas
you have a NLS problem I think. NLS is national Language Support and for you, I suggest you to read all around the BIDI format. could you read the docs about NLS and Hebrew on the support SAS site, for example : http://support.sas.com/techsup/unotes/le/005/005323.html St�phane. Selon Avi <aviben@BEZEQINT.NET.IL>: > Hello, > > I want to import a foreign text (Hebrew) from excel into a data set. > > The text looks very well in Excel but when imported in SAS, some characters > as dots, parenthesis behave strangely > > Here are some examples : > > .XXXXXXXX in Excel becomes XXXXXXX. in SAS > XXXXXXX(1 in Excel becomes 1)XXXXXXXXX in SAS > > Is there some "dramatic" way to force the text to appear as is in SAS > without inversing the special characters > > Your help will be very appreciated > > Avi > ...

Re: Assign variables to a new variable based on variable names in SAS #7
Chang, I agree with your assessment of Richard's code. I especially liked that he offered it without any chest pounding! Joe -----Original Message----- From: "Chang Y. Chung" <chang_y_chung@HOTMAIL.COM> Sent: Jan 16, 2004 11:19 AM To: SAS-L@LISTSERV.UGA.EDU Subject: Re: Assign variables to a new variable based on variable names in SAS Hi, Richard, Your data step, "monkeyshines" is one of the prettest I have ever seen. Really nice. The to-the-point array statement using the variable name wild character (":"); use of lbound() hbound() f...

Re: Assign variables to a new variable based on variable names in SAS #3
Here's a solution that builds a list of subscripts in macro variables named like the 'a_' columns in the input dataset. 'a_' fields are referenced by the subscript from the array they're defined to be part of: data stuff; a_2003q4 = 44; a_2003q1 = 11; a_2003q2 = 22; a_2003q3 = 33; n = 'a_2003q3'; run; proc sql noprint; create table columns as select name from sashelp.vcolumn where libname = 'WORK' and memname = 'STUFF' and name eqt 'a_' order by name ; select compbl('...

Re: Assign variables to a new variable based on variable names in SAS #5
Hi Chang & V - I'm confused as usual - did you mean this? 142 data one; 143 a_1995q3 = 1; 144 a_1995q4 = 2; 145 a_1997q1 = 3; 146 a_2003q4 = 5; 147 n = "2003q4"; 148 run; NOTE: The data set WORK.ONE has 1 observations and 5 variables. NOTE: DATA statement used: real time 0.01 seconds cpu time 0.01 seconds 149 150 data two; 151 set one; 152 call symput('n', n); 153 new_a = 'a_'||resolve(n); 154 put new_a=; 155 run; new_a=a_2003q4 NOTE: There were 1 observations read from the data set WORK.ONE...

Re: Assign variables to a new variable based on variable names in SAS #6
Hi, Richard, Your data step, "monkeyshines" is one of the prettest I have ever seen. Really nice. The to-the-point array statement using the variable name wild character (":"); use of lbound() hbound() functions; use of _i_ for index variable; short but intuitive variable and array names like aVars, aBase, and aMap; use of intnx and intck functions, reading the returned variable name with ??yyq6. format, anticipation of range checking, and all the work was done in essentially a single line!("a_new = aVars[aMap[qtrIndex]];") ... I learn a lot just by reading your...

Re: Assign variables to a new variable based on variable names in SAS #4
On Thu, 15 Jan 2004 11:02:05 -0800, W M <mwx74@HOTMAIL.COM> wrote: >I have met the following problem and I need your expert help. >The variable names in the data set looks like this: > >a_1995q3 a_1995q4 a_1997q1 ........... a_2003q4 n > Is there a way like > >new_a=a_{value of n} ? > >Because of the compilation of data step, you cannot do > >data new; set old; >call symput("name", n); >new_a=a_&n; (wrong !) >run; Hi, V, Following up on Paul (Choate)'s idea, this seems to work. This would serve as an example of putting an...

Re: How to read a SAS log into a SAS dataset.
lazybone2k@GMAIL.COM wrote: > >Dear SAS-L listers, >This may be the millionth time somebody is asking this question " how to >read a SAS log into a SAS dataset?". I looked at previous posts and >gathered info from various SUGI papers and found a way to get the log and >read it. But i dont know for some reason its not working. Please help me. >I used a Proc printto procedure to print the log to a external file >location and try to read in the log and create a SAS dataset which will >contain info about Filename, Owner name, Group name, Elapsed time, CPU >time, Dataset name. >***************Sample log file******************************** > data Purchmeta_US (keep=Name Start Length Description); >SYMBOLGEN: Macro variable METAPATH resolves >to /export/home/anjapara/838594.meta >41 infile "&metapath" ; >42 input @ 'Field name="' name1 :$17. @; >43 a=index(name1,'" '); >44 name=substr(name1,1,a-1); >45 input @'col="' Start :$3. @ 'len="' length :$1.@; >46 input @'<Description>' Desc &$100.; >47 i=index(Desc,'</'); >48 description=substr(Desc,1,i-1); >49 run; > >NOTE: The infile "/export/home/anjapara/838594.meta" is: > File Name=/export/home/anjapara/838594.meta, > Owner Name=anjapara,Group Name=rg...

Re: Converting Macro Variable to a SAS Dataset Variable
Refer to my previous answer; if you put them in a data set then = transpose the data set, you avoid macro variables altogether. However, to answer = the=20 question: data newtable; informat p1 8.; p1=3D&p1; run; To assign character variables, use the macro variable in double quotes informat char_var $20.; char_var=3D"&macro_var"; -Mary ----- Original Message -----=20 From: Siddharth Jain=20 To: SAS-L@LISTSERV.UGA.EDU=20 Sent: Wednesday, March 18, 2009 10:22 AM Subject: Converting Macro Variable to a SAS Dataset Variable If I have a macro variable p1 where %put <<p1>>; results in <<p1>> = 01,02,03,06 How do I bring value of p1 to a dataset. Can I make a dataset variable = which has the same values as of p1. Thanks in advance for your help, Siddharth ...

Re: Is it possible to read a sas dataset NOT using sas?
You might try the Universal OLE DB driver. Docs at: http://tinyurl.com/2cmgcf Driver page at: http://tinyurl.com/2hbc23 I think this should allow you to read a sas data set but not write to it. Also, the driver does not support much beyond a Select * clause. Phil Rack www.minequest.com -----Original Message----- From: SAS(r) Discussion [mailto:SAS-L@LISTSERV.UGA.EDU] On Behalf Of RolandRB Sent: Tuesday, March 18, 2008 9:44 AM To: SAS-L@LISTSERV.UGA.EDU Subject: Is it possible to read a sas dataset NOT using sas? Is it possible to read a sas dataset NOT using sas and have observations and variables etc. rather than having meaningless chunks of text? ...

Re: Parse Variable Name into SAS Variable Value
Try vname() function: 136 data _null_; 137 prem_disc_12_31_1987=23; 138 date_prem_disc=compress(vname(prem_disc_12_31_1987),'_abcdefghijklmnopqrstuvwxyz'); 139 put date_prem_disc=; 140 run; date_prem_disc=12311987 NOTE: DATA statement used: -----Original Message----- From: Tom Denton [mailto:denton@DUKE.EDU] Sent: Friday, August 15, 2003 8:03 AM To: SAS-L@LISTSERV.UGA.EDU Subject: Parse Variable Name into SAS Variable Value Can anyone tell me how to parse out a variable name into sas variable value. For example let's say I have a variable called prem_disc_12_31_1987 I'd like to set the date variable date_prem_disc equal to the sas date value for 12311987 (parsed from the variable name above). Any ideas? ...

Re: urgent : Convert SAS array in to sas variables
Shailesh, Why would you want to do what you ask? What you are asking would create the variable for all observations, but the variables' values would be missing values for every observation except the one on which it is based. Art ----- On Sat, 3 May 2008 23:34:44 -0700, Shailesh <shailesh.tewari@GMAIL.COM> wrote: >In my dataset I have an array variable , say A which has values like >Observation 1 - A[1]= 23 ,A[2]=34, A[3]=45 >Observation 2 - A[11]= 23 ,A[12]=34, A[13]=45 > >I want to create sas variables which should have name A61, A62 , A63, >A64 .......... >Similarly for second observation these would be A71, A72, >A73 , A74......... > > >in the same datastep. > >Any help ? > >Regards, >Shailesh ...

what does SHIFT-left-or-right of up-down-left-right do?
Well, I know about shift up-and-down: shift-right ("red" or whatever) up and down on choose-box, HIST, things like that, take the cursor all the way to the beginning or the end. shift-left ("white") on up and down scroll the screen-full up or down (the FIRST such click *stupidly* goes to the final CURRENTLY-ON-SCREEN choice or whatever (meaning TWO double-button-pushes to scroll-down that FIRST time.) What are some of the OTHER possibilities, ie with the left and right arrows? Oh, apparantely undocumented, I've found (via mistaken key-pushes) that RIGHT-arrow will do a SWAP (on stack), and that an UP-arrow gets you into HIST (that HIST is *one nice feature*!) Other tricks with those arrows? Thanks! David David Combs wrote: > Well, I know about shift up-and-down: > > shift-right ("red" or whatever) up and down on > choose-box, HIST, things like that, take the > cursor all the way to the beginning or the end. > > shift-left ("white") on up and down scroll the > screen-full up or down (the FIRST such click > *stupidly* goes to the final CURRENTLY-ON-SCREEN > choice or whatever (meaning TWO double-button-pushes > to scroll-down that FIRST time.) > > > What are some of the OTHER possibilities, ie with the > left and right arrows? > > > Oh, apparantely undocumented,...

Re: Convert sas date variable and time variable to a datetime
On Wed, 1 Nov 2006 12:00:36 -0500, souga soga <souga1234@GMAIL.COM> wrote: >Hi, > >I have a date variable and a separate time variable, i would like to >concatenate the two and >convert them to a SAS datetime variable. > >DATA test; >myDate="01JAN90"D ; myTime="01:30:30"T ;OUTPUT ; >myDate="02JAN90"D ; myTime="01:30:31"T ;OUTPUT ; >RUN; > >Thanks, >Sa Try myDateTime = dhms(myDate,0,0,myTime); ...

Re: newbie question re:reading in and recoding SAS dataset
Jan, I agree with Toby that you have a problem with the variable brainmt. It is commented out of your first else statement, but still exists in the initial if statement. A second potential problem seems to exist in the first else statement. While you indicate that you want case to be equal to one for anyone who had some kind of subsequent cancer, your code only counts them if they have had every type of cancer (except for the missing commented out brainmt. Might you have meant to code: >300 else if cancer =1 and (any_skin=1 or any_meln=1 or anymouth=1 >or any_lung=1 or >300! anybowel=1 >301 or any_stom=1 or any_panc=1 or anyliver=1 or anylymph=1 or >any_leuk=1 or any_mm=1 >301! or >302 any_kidn=1 or any_blad=1 or anybreas=1 or anyutern=1 or >any_test=1 or anyovary=1 >302! or >303 anyprost=1 or anyother=1 or /*brainmt=1 or */ unclr_mb=1 or >unclr_mt=1 or >303! unclr_st=1 or >304 anycerv=1 or anycolo=1 or anyrect=1 or anythyr=1 or >anyesoph=1 or brain_mb=1 or >304! anyutoth=1) >305 then case =1; Finally, you are not assigning any value to case if Cancer is missing, but that may be by design. Art --------- On Thu, 22 Sep 2005 09:47:27 -0700, J McClure <mc006@PACBELL.NET> wrote: >Hi, >I am a doctoral student in epidemiology. I have no support at school for >SAS programming and would greatly appreciate help creating a new >variable from my dataset. (The SAS programming skills a...

Re: Converting Macro Variable to a SAS Dataset Variable #4
Siddharth, If I understand properly, you are looking to identify, for each subject / organ code (where here is organ code, by the way - is that lasticd?), whether there is a difference between one visit and the next? For that I imagine you're best off using one of the various stat procs, I'm not an expert in that area but there are plenty of ways of analyzing change over (variable) of (variable). You could also normalize your data (if it's not already, that's not clear) by visit date and create three visit date tables, one for each date of interest, and then merge them together, then creating a fourth variable as the difference between the three. -Joe On Wed, Mar 18, 2009 at 10:41 AM, Siddharth Jain <sjain@aveopharma.com>wrot= e: > Hello Joe, > > > > Thanks for your response. Below is the code I have up till now: > > > > Per subjid per visit per organ code, I have to see whether result is > changing or not. > > > > Thanks, > > Siddharth > > > > > > > > *data* la11; > > set la; > > if lacat in ('NTL=92) and subjid in ('101-001'); > > keep subjid visitnum lasitcd lastresc; > > *run*; > > > > *proc* *sql*; > > select distinct LASTRESC into :p1 separated by ',' from la11 wherevisi= tnum eq > 1; > > select distinct LASTRESC into :p2 separated by ',' from la11 wherevisi= tnum eq > 222;...

Re: Converting Macro Variable to a SAS Dataset Variable #2
Sounds like you should address this at the step where you create the macro variable; instead of creating a macro variable, create a dataset (or a dataset variable). (I assume this is related to your other query, which indicates that you create this macro variable in PROC SQL). Can you post some code and sample data for how you arrive at &p1 in the first place? -Joe On Wed, Mar 18, 2009 at 10:22 AM, Siddharth Jain <sjain@aveopharma.com>wrote: > If I have a macro variable p1 where %put <<p1>>; results in <<p1>> > 01,02,03,06 > > > How do I bring value of p1 to a dataset. Can I make a dataset variable > which > has the same values as of p1. > > > Thanks in advance for your help, > Siddharth > ...

Re: SAS Intrnet question, passing macro variables to SAS.
Jia, You have to mask tokens that appear in pairs. In your example precede the single quote (') with a % sign. Try: &libdata=test&citystate=%str(%'Birmingham, AL%',%'Dothan, AL%',%'Huntsville,AL%') Nikhil Sardesai -----Original Message----- From: Michael L. Davis [mailto:michael@BASSETTCONSULTING.COM] Sent: Friday, January 28, 2005 5:13 AM To: SAS-L@LISTSERV.UGA.EDU Subject: Re: [SAS-L] SAS Intrnet question, passing macro variables to SAS. Hello Jia and other SAS-L Friends, I'm not sure I know the answer but I have some ideas. However, first, I have a question. Are you building the URL outside of an HTML form? If you are, the following link on the SAS web site might interest you: http://support.sas.com/faq/039/FAQ03925.html You might also want to look at the following link: http://support.sas.com/rnd/web/intrnet/dispatch82/input.html Look at the section titled "Specifying Name/Value Pairs in a URL". Most likely, the ampersands might be playing a role. SAS/IntrNet strips off "unsafe characters" unless you tell it not to do so. Please see: http://support.sas.com/rnd/web/intrnet/dispatch82/srvusaf.html Part of that link states: The APPSRV_UNSAFE function returns the complete, original value of an input name/value pair. Normally unsafe characters (see the UNSAFE option) are stripped from input values before creating the input macro variables. This is done so that macro variables may be freely used in a a...

Re: urgent : Convert SAS array in to sas variables #2
On Sat, 3 May 2008 23:34:44 -0700, Shailesh <shailesh.tewari@GMAIL.COM> wrote: >In my dataset I have an array variable , say A which has values like >Observation 1 - A[1]= 23 ,A[2]=34, A[3]=45 >Observation 2 - A[11]= 23 ,A[12]=34, A[13]=45 > >I want to create sas variables which should have name A61, A62 , A63, >A64 .......... >Similarly for second observation these would be A71, A72, >A73 , A74......... > > >in the same datastep. > >Any help ? > >Regards, >Shailesh Arrays are DATA *step* structures. They do not exists in data *sets*. Please post an example showing the data set you have and what you need (or think you need). ...

Web resources about - Re: Read a variable from Right to Left - comp.soft-sys.sas

Variable - Wikipedia, the free encyclopedia
Text is available under the Creative Commons Attribution-ShareAlike License ;additional terms may apply. By using this site, you agree to the ...

Westpac interest rate rise is one of many variable loan rate rises
WESTPAC is not alone in hitting its owner-occupier customers with a surprise interest rate rise, as dozens of other variable rate home loans ...

Airbnb upgrades variable pricing tool for hosts
Online home rental group Airbnb is rolling out an upgraded variable pricing tool that automatically raises or cuts room rates based on supply ...

Commonwealth Bank raises variable home loan rates
Home owners' mortgage costs are set to rise by hundreds of dollars a year, after the Commonwealth Bank became the latest bank to hike interest ...

CBA lifts variable home loan rates to offset costs associated with stricter capital requirements
The Commonwealth Bank to lift its home loan interest rates independently of the Reserve Bank to partially offset costs associated with stricter ...

Washington Square Signs Spielbergs, Choi Joins Variable and More
... films and an episode of the HBO comedy series "Girls," on which he plays the role of Ray Ploshansky. New York-based creative collective Variable ...

Mozilla moves Firefox to variable release schedule
... schedule process "carefully" and learning "a lot" from it in the past years, Mozilla has announced that Firefox is now moving to a variable ...

"You have to ignore many variables to think women are paid less than men. California is happy to try." ...
Writes Sarah Ketterer in The Wall Street Journal in "The ‘Wage Gap’ Myth That Won’t Die" (which you can get to without subscribing if you Google ...

Staley: 'A lot of different variables...been a hard year'
... 41° Navigation Home Giants A's Sharks Warriors Kings 49ers Raiders Quakes Insiders More Tickets Shop Watch Staley: 'A lot of different variables...been ...

When your environment variables are showing
There are embarrassing moments in life. There is the teacher calling you out as a child in class as you stare out the window wistfully imagining ...

Resources last updated: 3/18/2016 2:30:15 PM