f



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);
0
nospam1405 (4666)
11/1/2006 5:15:24 PM
comp.soft-sys.sas 142828 articles. 3 followers. Post Follow

0 Replies
695 Views

Similar Articles

[PageSpeed] 6

Reply:

Similar Artilces:

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 ...

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: 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). ...

Re: Converting Macro Variable to a SAS Dataset Variable #3
Send mail to the list not a person on the list! data visit1; set la11; if visitnum=1; lastresc1=lastresc; keep subjid lastresc1; run; data visit222; set la11; if visitnum=222; lastresc222=lastresc keep subjid lastresc222; run; data visit777; set la11; if visitnum=777; lastresc777=lastresc; keep subjid lastresc777; run; data new; merge visit1 visit222 visit777; by subjid; run; Proc Transpose could also be used on your first data set to flip it. -Mary ----- Original Message ----- From: Siddharth Jain To: Mary Sent: Wednesday, March 18, 2009 10:59 AM Subject: RE: Converting Macro Variable to a SAS Dataset Variable Hello Mary, 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') and subjid in ('101-001'); keep subjid visitnum lasitcd lastresc; run; proc sql; select distinct LASTRESC into :p1 separated by ',' from la11 where visitnum eq 1; select distinct LASTRESC into :p2 separated by ',' from la11 where visitnum eq 222; select distinct LASTRESC into :p3 separated by ',' from la11 where visitnum eq 777; %put <<p1>> &p1 <<p2>> &p2 <<p3> &p3; From: Mary [mailto:mlhoward@avalon.net] Sent: Wednesday, March 18, 2009 11:54 AM To: Siddharth Jain; SAS-L@LISTSERV.UGA.EDU Subject: Re: Converting Macro Variable t...

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: Convert character variable into a sas date
If it's a SAS date (currently a number around 17,000) then format it with a date format like Date9. or mmddyy10. : Format Date_of_Birth Date9.; If a datetime (a number currently around 1.5 billion) then you'll need to convert it to a date first: Date_of_Birth=datepart(Date_of_Birth); hth Paul Choate DDS Data Extraction (916) 654-2160 -----Original Message----- From: SAS(r) Discussion [mailto:SAS-L@LISTSERV.UGA.EDU] On Behalf Of rss Sent: Friday, October 06, 2006 2:41 PM To: SAS-L@LISTSERV.UGA.EDU Subject: Convert character variable into a sas date Hi, I had to pull a file from unix over to windows. I tried to do this with a sas data set but each time I tried to read the file it said some table didn't exist. I reformatted the sas data set into a csv file and ported it over to windows. That said I was able to create a new data set but now my date time variable "Date_of_Birth" is coming in as a character*18 mmdddyyyy:00:00:00 How can I convert this back into a sas date (mmdddyyyy) would be fine. I tried the following: dob=input(date_of_birth,date9.); and that creates a numeric value that corresponds to a sas date but it is being stored in my data set as a numeric. How can I change the way it's stored in the data set so that it looks like a date when viewed? I also found: endate=date(); age=intck('year',dob,endate); works and calculates the age of someone to the nearest year. I could also specify months or days as the interval....

Re: Convert text variable to SAS date #2
Drat Harry. I wanted to answer that one. :-) ...

Re: Convert character variable into a sas date #2
On Fri, 6 Oct 2006 14:49:52 -0700, Choate, Paul@DDS <pchoate@DDS.CA.GOV> wrote: >If it's a SAS date (currently a number around 17,000) then format it >with a date format like Date9. or mmddyy10. : > >Format Date_of_Birth Date9.; > >If a datetime (a number currently around 1.5 billion) then you'll need >to convert it to a date first: > >Date_of_Birth=datepart(Date_of_Birth); > >hth > >Paul Choate >DDS Data Extraction >(916) 654-2160 > >-----Original Message----- >From: SAS(r) Discussion [mailto:SAS-L@LISTSERV.UGA.EDU] On Behalf Of rss >Sent: Friday, October 06, 2006 2:41 PM >To: SAS-L@LISTSERV.UGA.EDU >Subject: Convert character variable into a sas date > >Hi, > >I had to pull a file from unix over to windows. I tried to do this >with a sas data set but each time I tried to read the file it said some >table didn't exist. I reformatted the sas data set into a csv file and >ported it over to windows. > >That said I was able to create a new data set but now my date time >variable "Date_of_Birth" is coming in as a character*18 >mmdddyyyy:00:00:00 How can I convert this back into a sas date >(mmdddyyyy) would be fine. > >I tried the following: > >dob=input(date_of_birth,date9.); > >and that creates a numeric value that corresponds to a sas date but it >is being stored in my data set as a numeric. Right. SAS dates are just a convent...

Re: how to convert unix date/time to SAS datetime format?
Hi, the problem is, that the base-year for a unix timestamp is different to SAS. SAS has 01jan1960:00:00:00 and unix 01jan1970:00:00:00 as far as I know. So you have to add 10 years in seconds to the unix-datetime. Example: data a; unix=1143636054; sasdif=dhms("01jan1970"d,0,0,0); put unix datetime20.; sas=unix+sasdif; put sas datetime20.; run; I don't know how much seconds are between 01jan1960 and 01jan1970, so I let SAS do the work (sasdif=???) You can write that to a macro-variable so you must not recalculate it anytime you need it... Regards, Gerhard On Mon, 9 Oct 2006 09:56:31 -0400, Wensui Liu <liuwensui@GMAIL.COM> wrote: >Dear all, > >I have a vector of unix time, say 1143636054, but don't know how to >convert it to SAS date time. > >Thanks. ...

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 #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 #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 #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 convert date and time to sas date?
Try DATEPART() function in order to extract just the date like : format MyDate yymmdd10.; MyDate =3D DATEPART(YourDateTimeVar); Hope it helps... Patrice Bourdages Industrial Alliance, home and car insurance -----Message d'origine----- De : Saqi [mailto:saqi2000@TOTALISE.CO.UK] Envoy=E9 : 9 f=E9vrier, 2004 12:15 =C0 : SAS-L@LISTSERV.UGA.EDU Objet : How to convert date and time to sas date? Hi their, I would like to convert the following 12FEB2004:00:00:00 in to 12/02/04. Can you please tell me how can I do this? Thanks Saqi ...

Re: how to convert unix date/time to SAS datetime format? #2
Thanks, Gerhard, It is exactly what I am looking. wensui On 10/9/06, Gerhard Hellriegel <gerhard.hellriegel@t-online.de> wrote: > Hi, > the problem is, that the base-year for a unix timestamp is different to SAS. > SAS has 01jan1960:00:00:00 and unix 01jan1970:00:00:00 as far as I know. > So you have to add 10 years in seconds to the unix-datetime. Example: > > data a; > unix=1143636054; > sasdif=dhms("01jan1970"d,0,0,0); > put unix datetime20.; > sas=unix+sasdif; > put sas datetime20.; > run; > > I don't know how much seconds are between 01jan1960 and 01jan1970, so I let > SAS do the work (sasdif=???) > You can write that to a macro-variable so you must not recalculate it > anytime you need it... > Regards, > Gerhard > > > > > On Mon, 9 Oct 2006 09:56:31 -0400, Wensui Liu <liuwensui@GMAIL.COM> wrote: > > >Dear all, > > > >I have a vector of unix time, say 1143636054, but don't know how to > >convert it to SAS date time. > > > >Thanks. > -- WenSui Liu (http://spaces.msn.com/statcompute/blog) Senior Decision Support Analyst Cincinnati Children Hospital Medical Center ...

Re: How to convert date and time to sas date? #2
Saqi, Is your original date and time field a SAS datetime variable? If yes skip the first two lines in the data step below. The display format you are looking for is ddmmyys8. The S before the 8 indicates that you want a slash to separate the day, month and year places. data _null_ ; char = "12FEB2004:00:00:00" ; dt = input ( char , datetime. ) ; d = datepart(dt) ; put d ddmmyys8. ; run ; _________________________________ Venky Chakravarthy E-mail: swovcc_AT_hotmail_DOT_com -----Original Message----- From: Saqi [mailto:saqi2000@TOTALISE.CO.UK] Sent: Monday, February 09, 2...

urgent : Convert SAS array in to sas variables
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 On May 4, 2:34=A0am, Shailesh <shailesh.tew...@gmail.com> wrote: > In my dataset I have an array variable , say A which has values like > Observation 1 - A[1]=3D 23 ,A[2]=3D34, A[3]=3D45 > Observation 2 - A[11]=3D 23 ,A[12]=3D34, A[13]=3D45 > > I want to create sas variables which should have name A61, A62 , A63, > A64 .......... > Similarly for second observation these would be =A0 =A0 =A0 =A0 =A0 A71, A= 72, > A73 , A74......... > > in the same datastep. > > Any help ? > > Regards, > Shailesh A SAS ARRAY is typically made up of variables, even if defined as _TEMPORARY_. Please share more code to explain how you have constructed the SAS DATA step logic thus far. You could introduce DATA step logic that reads observations and uses the _N_ value and a SAS variable counter to determine an ARRAY index/ subscript value for assigning a new variable of your choice. Here is a very, very obscure (it makes unstated assumptions) DATA step example, however it demonstrates the use of input and output ARRAYs and a computed index variable to assign a parti...

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: Converting variables with SAS
Hi Knuako. The variable (column) 't' can only be one type - character OR numeric, but not both. In this case it appears to be a character variable since it has non-numeric values. So, I am a bit confused about your first question. If the different EFFECTS (I, t) came from different datasets that were set together, you would have recieved an error message indicating that the variable 't' is defined as both character and numeric, at which point you would have to do something about it. One solution would be to: 1. rename the variable 't' in the SET step in the input datasets to be distinct 2. create a new variable (e.g. char_t) in the data step declaring it as a character variable (attrib char_t length=$1.;) 3. assign it to the 't' variables from the input data sources 4. drop the 't' variables from the output data For your second question, rather than creating multiple datasets, how about creating 1 indicator variable in 1 output dataset that indicates what value of 't' the current observation has? Then you could use this indicator variable in subsequent processing. For example... t_blnk=t='-'; OR if t='-' then t_ind='B'; else t_ind='N'; Satindra. On Tue, Jul 15, 2008 at 12:16 PM, Knuako <asom77@hotmail.com> wrote: > Hello everyone, > Could someone help me with the SAS code for the work below? > Converting variables: > I have a dataset( from a library) called dsRiver a...

Re: how to convert character variable to a date variable
alberthz@STANFORD.EDU wrote: >I have a variable like: >20010101 >20010102 >20010103 >20020101 >...... > > >it's date in fact, but when I import it,the SAS recognize it as character >variable. > > >How can I convert it to a date variable or numerical variable? It depends. [1] How are you 'importing' it? By 'import', do you mean that you're using PROC IMPORT? Or are you using the Import wizard? Or are you using a DATA step to read the file? [2] What are you importing from? If it is being iported from Excel or Oracle or MS SQL ...

Re: conditionally (re-)format SAS date into new age variable #2
Summary: Conditional informat with INPUTN #iw-value=1 ; Stephen, This is a hint of how to get started. data w ; input info $ fmt $ len var $ ; cards ; 73 f 8 age 12/20/54 anydtdte 8 date -5647 f 8 date ; data q ; set w ; if var = "age" then age = inputn ( info , fmt , len ) ; else if var = "date" then date = inputn ( info , fmt, len ) ; run ; I chose to build real specs into the data. You might find it good enough to assume that when INFO has a length of two or less that it is an a...

Re: Manipulation of date variables in SAS
Chaix, Yes there is. first make sure your two dates are SAS date values. For the date you showed us you could use input function or statement (as the case may be) with the yymmddw. informat. I will leave the other date to you to convert to a SAS date value if it already isn't. Then use the intck function to compute the dayes between the two: NumOfDays = intcj('Day',<start date>,<ending date>) ; HTH Toby Dunn From: Basile Chaix <chaix@U444.JUSSIEU.FR> Reply-To: Basile Chaix <chaix@U444.JUSSIEU.FR> To: SAS-L@LISTSERV.UGA.EDU Subject: Manipulation of...

Web resources about - Re: Convert sas date variable and time variable to a datetime - 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 6:34:15 AM