BookmarkSubscribeRSS Feed
ogarduno
Obsidian | Level 7

I have the following question to answer:

 

The main outcome of interest is whether the defendant was arrested again prior to his/her disposition (trial or court appearance) date. create a variable called 're_arrest' that equals one if the defendant was arrested prior to trial and zero otherwise e.g. imagine person 1 was arrested three times

 

caseid personid arrest_date    dispos_date  re_arrest

123        1          2012-01-01     2012-04-05    0

1344       1         2012-06-05     2012-09-13     1

1451       1         2012-07-09     2012-11-21     0

 

The dates a character value so i want to convert them into a sas date. I was thinking of approaching this by creating an if and then statement so if the date is in between the disposition date it would create 1 in the new variable. However, I'm having trouble inputting the csv file into sas and converting it into a sas date. Can anyone help me and if my approach is feasible? 

6 REPLIES 6
antonbcristina
SAS Employee

Can I ask how you're reading in the CSV file?

ogarduno
Obsidian | Level 7
I'm tired using filename infile procedure and proc import but none to my
luck
antonbcristina
SAS Employee

Can you post your code and log? It will help to figure out what is going on.

ogarduno
Obsidian | Level 7

filename inp1 'c:desktop\case.csv';

 

data case;

infile inp1;

informat arrest_date mmddyy10. dispos_date mmddyy10.;

input case_id arrest_date dispos_date;

run;

 

proc print;

run;

ballardw
Super User

@ogarduno wrote:

filename inp1 'c:desktop\case.csv';

 

data case;

infile inp1;

informat arrest_date YYMMDD10. dispos_date YYMMDD10.;

input case_id arrest_date dispos_date;

run;

 

proc print;

run;


Your dates obviously start with Years not months. You should have gotten many "invalid data" messages in the log.

It usually helps to add a FORMAT statement to display the values when you read them as well.

ballardw
Super User

@ogarduno wrote:

I have the following question to answer:

 

The main outcome of interest is whether the defendant was arrested again prior to his/her disposition (trial or court appearance) date. create a variable called 're_arrest' that equals one if the defendant was arrested prior to trial and zero otherwise e.g. imagine person 1 was arrested three times

 

caseid personid arrest_date    dispos_date  re_arrest

123        1          2012-01-01     2012-04-05    0

1344       1         2012-06-05     2012-09-13     1

1451       1         2012-07-09     2012-11-21     0

 

The dates a character value so i want to convert them into a sas date. I was thinking of approaching this by creating an if and then statement so if the date is in between the disposition date it would create 1 in the new variable. However, I'm having trouble inputting the csv file into sas and converting it into a sas date. Can anyone help me and if my approach is feasible? 


Show 1) the code you used to create the SAS data set from the CSV and 2) a copy few lines of the data AS TEXT (do not use Excel use something like Notepad or even the SAS editor), paste a few rows of the data into a code box here opened using the forum {I}

icon. Change any sensitive data before pasting it here.

 

The dates should read just fine with proc import unless 1) they have quotes around them in the CSV such as

123,1,'2012-01-01','2012-04-05',0

or the dates come in different formats or possibly the first few rows are missing the dates. Proc Import guesses variable types and formats from a small number of rows and changes or missing values make those "guesses" less useful.

 

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!

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
  • 6 replies
  • 874 views
  • 0 likes
  • 3 in conversation