BookmarkSubscribeRSS Feed
nickb
Calcite | Level 5
I have a tab delimited file and basically I want to read row 4 (date value) and put it into a column. I also want to read only rows that have a valid time and data. Below is an example of the file and program:

# ----------------------------------------

Visits for all visitors
April 23, 2010 April 23, 2010 ********want this in a column
# ----------------------------------------

# ----------------------------------------
# Graph
# ----------------------------------------
Hour All Visits (Segment) Traffic (Segment) Traffic (Segment)
00:00:00 492 0 492
01:00:00 259 0 259
02:00:00 130 0 130
03:00:00 100 0 100
04:00:00 66 0 66
05:00:00 99 0 99
06:00:00 242 6 236
07:00:00 597 80 517
08:00:00 1,106 268 838
09:00:00 1,421 383 1,038
10:00:00 1,518 438 1,080
11:00:00 1,524 419 1,105
12:00:00 1,436 321 1,115
13:00:00 1,385 243 1,142
14:00:00 1,252 158 1,094
15:00:00 1,299 142 1,157
16:00:00 1,178 87 1,091
17:00:00 1,025 16 1,009
18:00:00 928 7 921
19:00:00 971 3 968
20:00:00 992 3 989
21:00:00 998 3 995
22:00:00 933 0 933
23:00:00 731 0 731
# -------------------------------------------------------------------------------- causing issues in log

data va;
infile 'D:\Temp\test1.csv' dlm='09'x FIRSTOBS=11;
INPUT Time $ Visits $ CampusTraffic $ OffCampusTraffic $ ;
5 REPLIES 5
LinusH
Tourmaline | Level 20
You could use if = _n_ 4 then... to assign your master date. Have this column in a retain statement.

To check whether a date is valid you could just input there value using appropriate date format.
Testing the other data depends on what is valid data. Non-missing? Using (subsetting) if statments seems to be the most straightforward way to do it.

/Linus
Data never sleeps
Peter_C
Rhodochrosite | Level 12
remove that firstobs=[pre]data va;
infile 'D:\Temp\test1.csv' dlm='09'x truncover ;
retain visitor_date '12345678901234567890' ;
if visitor_date =:'1234567890' then do ;
input @'Visits' ;
input ;
visit_date = _infile_ ;
delete;
end ;
input hour ? @ ;
if _error_ then do;
_error_ = 0 ;
delete ;
end ;
input allv trafS1 trafs2 ;
label allv='All Visits' trafs1= 'Campus Traffic' trafs2='Off-Campus Traffic' ;
format hour hhmm. ;
informat hour time8. allv trafs: comma14. ;
run ;[/pre]
good luck
PeterC
Ksharp
Super User
My code is :

[pre]
data temp;
if _n_ =1 then do;
input @'visitors' / date $14. @'(Segment)' / Time $ Visits $ CampusTraffic $ OffCampusTraffic $ ;
output;
end;

input Time $ Visits $ CampusTraffic $ OffCampusTraffic $ ;
if Time ne '#' then output;
retain date;
datalines;
# ----------------------------------------

Visits for all visitors
April 23, 2010 April 23, 2010 ********want this in a column
# ----------------------------------------

# ----------------------------------------
# Graph
# ----------------------------------------
Hour All Visits (Segment) Traffic (Segment) Traffic (Segment)
00:00:00 492 0 492
01:00:00 259 0 259
02:00:00 130 0 130
03:00:00 100 0 100
04:00:00 66 0 66
05:00:00 99 0 99
06:00:00 242 6 236
07:00:00 597 80 517
08:00:00 1,106 268 838
09:00:00 1,421 383 1,038
10:00:00 1,518 438 1,080
11:00:00 1,524 419 1,105
12:00:00 1,436 321 1,115
13:00:00 1,385 243 1,142
14:00:00 1,252 158 1,094
15:00:00 1,299 142 1,157
16:00:00 1,178 87 1,091
17:00:00 1,025 16 1,009
18:00:00 928 7 921
19:00:00 971 3 968
20:00:00 992 3 989
21:00:00 998 3 995
22:00:00 933 0 933
23:00:00 731 0 731
# -------------------------------------------------------------------------------- causing issues in log
;
run;
proc print;
run;
[/pre]

Under SAS 9.0 version , code is OK. Message was edited by: Ksharp
nickb
Calcite | Level 5
When I run this I get 6 variables but no observations.
sbb
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10
Recommend some self-initiated desk-checking using a PUTLOG statement, as shown below -- you might consider placing multiples of these in various points in your program to display variables as the processing continues (increment "nn" value for identification with each being unique":

PUTLOG '>DIAG-nn>' / _all_;


Suggest you share your SAS log back with a post/reply to the forum for additional guidance, if needed further after the desk-checking exercise.

Scott Barry
SBBWorks, Inc.

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 5 replies
  • 947 views
  • 0 likes
  • 5 in conversation