BookmarkSubscribeRSS Feed
drschoe
Calcite | Level 5

I am using information from my ods and we keep the class times in military time and as a character field (0800) and I would like to be able to switch that into a more friendly time for example 8:00 a.m.

 

How would I go about changing that by using Computed Column??/

 

 

4 REPLIES 4
PeterClemmensen
Tourmaline | Level 20

Hi and welcome to the SAS Communities 🙂

 

You can do like this

 

data test;
   chartime='0800';
   time=input(cats(substr(chartime, 1, 2), ':', substr(chartime, 3, 2)), time5.);
   format time timeampm7.;
run;
drschoe
Calcite | Level 5

I am just starting out in SAS so if my field I am converting is Beginning_Time. It would look like this??

 

data test;
   chartime= Beginning_Time;
   time=input(cats(substr(chartime, 1, 2), ':', substr(chartime, 3, 2)), time5.);
   format time timeampm7.;
run;

 

I haven't quite learned how to insert code into the syntax quite yet  when I tried this in the Computed Column it just blew up on me.

 

 

PeterClemmensen
Tourmaline | Level 20

You can do like this. Insert your data set name instead of YourDatasetHere

 

data test;
   set YourDatasetHere;
   time=input(cats(substr(Beginning_Time, 1, 2), ':', substr(Beginning_Time, 3, 2)), time5.);
   format time timeampm7.;
run;
drschoe
Calcite | Level 5

Okay I put the info in as this for an advanced expression.

 

data test;
set t2.BEGIN_TIME;
time=input(cats(substr(t2.BEGIN_TIME, 1, 2), ':', substr(t2.BEGIN_TIME, 3, 2)), time5.);
format time timeampm7.;
run;

 

 

Then I clicked validate and it gave me this back.

 

PROC SQL NOEXEC;
SELECT (data test;
set t2.BEGIN_TIME;
time=input(cats(substr(t2.BEGIN_TIME, 1, 2), ':', substr(t2.BEGIN_TIME, 3, 2)), time5.);
format time timeampm7.;
run;) AS CALCULATION
FROM ODS_OPSU.SCHEDULE_OFFERING t1
INNER JOIN ODS_OPSU.MEETING_TIME t2 ON (t1.COURSE_IDENTIFICATION = t2.COURSE_IDENTIFICATION);
QUIT;

 

 

;*';*";*/;quit;run;
2 OPTIONS PAGENO=MIN;
3 OPTION DEBUG=DBMS_SELECT SQL_IP_TRACE=(NOTE, SOURCE);


4 PROC SQL NOEXEC;
5 SELECT (data test;
____
22
76
ERROR 22-322: Syntax error, expecting one of the following: !, !!, &, (, ), *, **, +, -, '.', /, <, <=, <>, =, >, >=, ?, AND,
BETWEEN, CONTAINS, EQ, EQT, GE, GET, GT, GTT, IN, IS, LE, LET, LIKE, LT, LTT, NE, NET, NOT, NOTIN, OR, ^, ^=, |, ||,
~, ~=.

ERROR 76-322: Syntax error, statement will be ignored.

6 set t2.BEGIN_TIME;
__
22
76
ERROR 22-322: Syntax error, expecting one of the following: MODE, TRANSACTION.

ERROR 76-322: Syntax error, statement will be ignored.

7 time=input(cats(substr(t2.BEGIN_TIME, 1, 2), ':', substr(t2.BEGIN_TIME, 3, 2)), time5.);
____
180
ERROR 180-322: Statement is not valid or it is used out of proper order.

8 format time timeampm7.;
WARNING: This SAS global statement is not supported in PROC SQL. It has been ignored.
9 run;) AS CALCULATION
_
180
NOTE: PROC SQL statements are executed immediately; The RUN statement has no effect.
ERROR 180-322: Statement is not valid or it is used out of proper order.

10 FROM ODS_OPSU.SCHEDULE_OFFERING t1
11 INNER JOIN ODS_OPSU.MEETING_TIME t2 ON (t1.COURSE_IDENTIFICATION = t2.COURSE_IDENTIFICATION);
12 QUIT;
NOTE: The SAS System stopped processing this step because of errors.
NOTE: PROCEDURE SQL used (Total process time):
real time 0.00 seconds
cpu time 0.01 seconds

13 %PUT SQL_IPTRACE_RESULT=&SYS_SQL_IP_ALL;
SQL_IPTRACE_RESULT=-1
14 OPTIONS SQL_IP_TRACE=(NONE);
15 QUIT; RUN;

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 4 replies
  • 1249 views
  • 0 likes
  • 2 in conversation