BookmarkSubscribeRSS Feed
malikah_sph
Calcite | Level 5

 

I need to format dates from the format of 15 Mar 2000 to the format of 03-15-2000 instead. I have tried the following code thus far:

 

data agemod;
set Tmp1;
rename Please_enter_your_date_of_birth_ = dob;
format dob yymmdd10.;
informat dob yymmdd10.;
run;

 

However it is not working. Can anyone provide assistance?

 

 

10 REPLIES 10
ballardw
Super User

Run proc contents on the TMP1 dataset or look at the column view in the SAS Explorer window to determine it's typle. It is very likely that the variable is actually text (character).

If that is the case then this should work:

data agemod;
   set Tmp1;
   dob= input( Please_enter_your_date_of_birth_,anydtdte32.);
   format dob yymmdd10.;
   drop Please_enter_your_date_of_birth_;
run;
malikah_sph
Calcite | Level 5

Thank you for your help but the code is still not working :(. I have run proc contents and dob actually comes up as numeric so that's not the problem. 

jklaverstijn
Rhodochrosite | Level 12

it will help if you provide a sample of your data, the proc comtents output from before and the log of your attempts. Snd what are your current unexpected results?

 

- Jan.

ballardw
Super User

Describe "Not working": NO results, unexpected results (give example of actual results and desired), errors (include with code and errors)

malikah_sph
Calcite | Level 5

There were no errors in the log but when I look at the data set, the column dob is empty. It just has dots and no actual data. 

ballardw
Super User

Run proc contents on your TMP1 data set and post the result here.

It may not here to Proc Print a few rows from TMP1 if you can share the data here:

Proc print data=tmp1 (obs=10);

run;

should print the first 10 rows.

malikah_sph
Calcite | Level 5

Here is a data sample:

 

 

SAS Output

Obs Record_ID Agreement_to_participate_____By_ Today_s_date_ I_agree_to_allow_my_contact_info inst inst1 inst2 inst3 inst4 inst5 inst6 inst7 inst8 inst9 inst10 inst11 inst12 inst13 inst14 inst15 inst16 inst17 inst18 inst19 inst20 inst21 inst22 inst23 inst24 inst25 inst26 inst27 inst28 inst29 inst30 inst31 inst32 inst33 New_Subject_ID What_is_your_sex_ What_sex_were_you_assigned_at_bi How_do_you_describe_yourself_ Have_you_undergone_treatment_for What_type_of_sex_reassignment_tr Did_you_begin_sex_reassignment_t Please_enter_your_date_of_birth_ Are_you_of_Hispanic_Latino_desce Please_select_one_or_more_catego Please_select_one_or_more_categ0 Please_select_one_or_more_categ1 Please_select_one_or_more_categ2 Please_select_one_or_more_categ3 Please_select_one_or_more_categ4 Select_the_highest_level_of_scho Select_your_total_HOUSEHOLD_inco Please_select_your_current_marit Please_select_your_current_emplo In_which_state_do_you_live_ Please_select_the_type_of_cancer When_you_were_diagnosed_with_bre When_were_you_diagnosed_with_thi What_type_of_treatment_s__have_y What_type_of_treatment_s__have_0 What_type_of_treatment_s__have_1 What_type_of_treatment_s__have_2 What_type_of_treatment_s__have_3 What_other_treatment_s__did_you_ Have_you_received_or_will_you_be Pain Fatigue Sleep_disturbance Memory_and_concentration Nausea_vomiting Poor_appetite Trouble_swallowing Dental_or_mouth_problems Weight_changes Balance_walking_mobility Loss_of_strength Tingling_or_numbness_in_feet___h Swelling_in_legs_or_arms__lymphe Osteoporosis_bone_health Hair_and_skin_issues Body_changes Bowel_or_bladder_changes Hot_flashes Sexual_issues Fertility_issues Managing_household_activities Caring_for_family_members Talking_about_cancer_with_family Returning_to_work Health_insurance Financial_concerns Debt_from_medical_bills Defining_a_new_sense_of_normal Managing_difficult_emotions__ang Coping_with_grief_and_loss Living_with_uncertainty Fear_of_recurrence Managing_stress Isolation_feeling_alone Intimacy_issues Looking_for_the_bright_side__gra Having_a_sense_of_well_being Changing_relationship_with_spous Finding_support_services Connecting_to_counseling_service Genetic_counseling__worry_about_ How_confident_are_you_that_you_c How_confident_are_you_that_you_0 How_confident_are_you_that_you_1 How_confident_are_you_that_you_2 How_confident_are_you_that_you_3 How_confident_are_you_that_you_4 How_confident_are_you_that_you_5 How_confident_are_you_that_you_6 Primary_care Oncology Other_specialties Mental_health Hospital_inpatient Hospital_outpatient Hospital_emergency_room Urgent_care Other__please_specify_ What_other_provider_or_places_of There_are_many_reasons_people_de There_are_many_reasons_people_d0 There_are_many_reasons_people_d1 There_are_many_reasons_people_d2 There_are_many_reasons_people_d3 There_are_many_reasons_people_d4 There_are_many_reasons_people_d5 There_are_many_reasons_people_d6 There_are_many_reasons_people_d7 There_are_many_reasons_people_d8 There_are_many_reasons_people_d9 There_are_many_reasons_people_10 There_are_many_reasons_people_11 There_are_many_reasons_people_12 There_are_many_reasons_people_13 There_are_many_reasons_people_14 There_are_many_reasons_people_15 What_is_the_other_reason_you_del Complete_ instn mod instc 1 2 3 4 5 6 7 8 9
1044Yes22APR2016YesWenatchee Valley (Confluence)   Katherine Kemble, DNP, FNP-C, AOCNP, ARNP                              Male     06OCT1945NoCheckedUncheckedUncheckedUncheckedUncheckedUnchecked4-year college graduate$75,000 to $99,999MarriedRetired ProstateDon't know13OCT2016CheckedUncheckedCheckedUncheckedUnchecked No, I have not or will not be receiving hormone therapy for this cancer.14.40 No Concerns0 No Concerns125 Extreme Concerns22433445 Extreme Concerns230 No Concerns2 30 (no concerns)0 (no concerns)4135 (extreme concerns)2444334 3333223.3333NoneNone2-3 timesNoneNone1 timeNoneNone  UncheckedUncheckedUncheckedUncheckedCheckedUncheckedUncheckedUncheckedUncheckedUncheckedUncheckedUncheckedUncheckedUncheckedUncheckedUncheckedUnchecked Complete2812
1043Yes11MAY2016YesCanton Mercy Medical Center Joan Edwards, RN, OCN                                Male     25DEC1954NoCheckedUncheckedUncheckedUncheckedUncheckedUncheckedHigh school graduate or GEDLess than $25,000DivorcedNot workingOHColorectal (including **bleep**)Don't know15JUL2016UncheckedCheckedCheckedUncheckedUnchecked No, I have not or will not be receiving hormone therapy for this cancer.....0 No Concerns0 No Concerns0 No Concerns0 No Concerns0 No Concerns0 No Concerns0 No Concerns0 No Concerns0 No Concerns0 No Concerns0 No Concerns0 No Concerns0 No Concerns0 No Concerns0 No Concerns 0 (no concerns)0 (no concerns)0 (no concerns)5 (extreme concerns)5 (extreme concerns).5 (extreme concerns).0 (no concerns)0 (no concerns)0 (no concerns).0 (no concerns)0 (no concerns)0 (no concerns)0 (no concerns)0 (no concerns)0 (no concerns) 0 (no concerns)0 (no concerns)3343333.2-3 times         CheckedUncheckedUncheckedUncheckedUncheckedUncheckedUncheckedUncheckedUncheckedUncheckedUncheckedUncheckedUncheckedUncheckedUncheckedUncheckedUnchecked Complete732
1042Yes05MAY2016YesCanton Mercy Medical Center Jane Westfall, RN, BSN, OSN                                Female     07AUG1975NoCheckedUncheckedUncheckedUncheckedUncheckedUncheckedSome college or 2-year degree$100,000 or moreMarriedWorking- as a paid employeeOHBreastStage 015NOV2016CheckedUncheckedUncheckedUncheckedCheckedTamoxifenYes, I am receiving hormone therapy.223110 No Concerns0 No Concerns0 No Concerns10 No Concerns30 No Concerns22220 No Concerns410 No Concerns11121.0 (no concerns)3213420 (no concerns)10 (no concerns)10 (no concerns)10 (no concerns)0 (no concerns)435 Totally confident3.5 Totally confident5 Totally confident.None2-3 times8 or more timesNone1 timeNoneNoneNone  CheckedUncheckedUncheckedUncheckedUncheckedUncheckedUncheckedUncheckedUncheckedUncheckedUncheckedUncheckedUncheckedUncheckedUncheckedUncheckedUnchecked Complete734
1041Yes02MAY2016YesNew England Cancer Specialists                               Dixie Knoll, FNP  Female     17JUL1972NoCheckedUncheckedUncheckedUncheckedUncheckedUncheckedSome college or 2-year degree$25,000 to $49,999DivorcedWorking- as a paid employeeMEBreastStage 115MAY2016CheckedUncheckedCheckedUncheckedUnchecked Yes, I am receiving hormone therapy.244.30 No Concerns0 No Concerns0 No Concerns30 No Concerns0 No Concerns0 No Concerns0 No Concerns10 No Concerns0 No Concerns0 No Concerns5 Extreme Concerns0 No Concerns0 No Concerns0 (no concerns)0 (no concerns)0 (no concerns)0 (no concerns)0 (no concerns)33.0 (no concerns)0 (no concerns)5 (extreme concerns).0 (no concerns)0 (no concerns)0 (no concerns)0 (no concerns)0 (no concerns)0 (no concerns)0 (no concerns)0 (no concerns)0 (no concerns).45 Totally confident445 Totally confident5 Totally confident.None6-7 timesNoneNoneNoneNoneNoneNone  CheckedUncheckedUncheckedUncheckedUncheckedUncheckedUncheckedUncheckedUncheckedUncheckedUncheckedUncheckedUncheckedUncheckedUncheckedUncheckedUnchecked Complete1522
1040Yes03MAY2016YesNew England Cancer Specialists                               Dixie Knoll, FNP  Female     04OCT1984NoCheckedUncheckedUncheckedUncheckedUncheckedUncheckedHigh school graduate or GEDDon't knowMarriedWorking- as a paid employeeMEBreastStage 215JUN2016CheckedCheckedCheckedUncheckedUnchecked No, I have not or will not be receiving hormone therapy for this cancer.233.0 No Concerns0 No Concerns10 No Concerns0 No Concerns0 No Concerns0 No Concerns10 No Concerns0 No Concerns0 No Concerns0 No Concerns0 No Concerns20 No Concerns410 (no concerns)0 (no concerns)1444110 (no concerns)0 (no concerns)22110 (no concerns)0 (no concerns)10 (no concerns)0 (no concerns)0 (no concerns)43423432None1 time1 timeNoneNoneNoneNoneNoneNone CheckedUncheckedUncheckedUncheckedUncheckedUncheckedUncheckedUncheckedUncheckedUncheckedUncheckedUncheckedUncheckedUncheckedUncheckedUncheckedUnchecked Complete1522
1039Yes26APR2016YesCanton Mercy Medical Center Jane Westfall, RN, BSN, OSN                                Female     14JUN1942NoCheckedUncheckedUncheckedUncheckedUncheckedUncheckedHigh school graduate or GEDLess than $25,000DivorcedRetiredOHBreastStage 115JUL2016CheckedUncheckedUncheckedUncheckedUnchecked Yes, I am receiving hormone therapy..1.20 No Concerns0 No Concerns0 No Concerns0 No Concerns10 No Concerns2 10 No Concerns10 No Concerns0 No Concerns0 No Concerns0 No Concerns0 No Concerns0 (no concerns)0 (no concerns)0 (no concerns)0 (no concerns)0 (no concerns).0 (no concerns).10 (no concerns)0 (no concerns)20 (no concerns)0 (no concerns)0 (no concerns)0 (no concerns)0 (no concerns)0 (no concerns)0 (no concerns)0 (no concerns)2..5 Totally confident335 Totally confident43None2-3 timesNoneNoneNoneNoneNoneNone  CheckedUncheckedUncheckedUncheckedUncheckedUncheckedUncheckedUncheckedUncheckedUncheckedUncheckedUncheckedUncheckedUncheckedUncheckedUncheckedUnchecked Complete734
1038Yes26APR2016YesEssentia Institute of Rural Health                           Jessica Nybakken, CNP      Female     19OCT1945NoCheckedUncheckedUncheckedUncheckedUncheckedUncheckedSome college or 2-year degreeDon't knowMarriedRetiredMNBreastStage 115AUG2016CheckedUncheckedCheckedUncheckedUnchecked Yes, I completed hormone therapy.11410 No Concerns0 No Concerns0 No Concerns0 No Concerns0 No Concerns0 No Concerns0 No Concerns0 No Concerns0 No Concerns30 No Concerns10 No Concerns40 No Concerns0 No Concerns0 (no concerns)0 (no concerns)0 (no concerns)0 (no concerns)22210 (no concerns)0 (no concerns)110 (no concerns)10 (no concerns)0 (no concerns)0 (no concerns)0 (no concerns)0 (no concerns)0 (no concerns)2..5 Totally confident435 Totally confident5 Totally confident3None2-3 timesNoneNoneNoneNoneNoneNone  UncheckedUncheckedUncheckedUncheckedUncheckedUncheckedUncheckedUncheckedUncheckedUncheckedUncheckedUncheckedUncheckedUncheckedUncheckedUncheckedUnchecked Complete911
1037Yes26APR2016YesEssentia Institute of Rural Health                           Jessica Nybakken, CNP      Female     05AUG1944NoCheckedUncheckedUncheckedUncheckedUncheckedUncheckedSome college or 2-year degreeLess than $25,000WidowedRetiredMNBreastStage 115OCT2016CheckedUncheckedCheckedUncheckedUnchecked Yes, I am receiving hormone therapy.2...0 No Concerns0 No Concerns0 No Concerns0 No Concerns0 No Concerns0 No Concerns0 No Concerns0 No Concerns10 No Concerns0 No Concerns10 No Concerns0 No Concerns0 No Concerns0 No Concerns0 (no concerns)0 (no concerns)10 (no concerns)0 (no concerns)10 (no concerns).0 (no concerns)0 (no concerns)0 (no concerns)20 (no concerns)10 (no concerns)0 (no concerns)0 (no concerns)0 (no concerns)0 (no concerns)0 (no concerns)1345 Totally confident225 Totally confident5 Totally confident41 time2-3 timesNoneNoneNoneNoneNoneNone2-3 timesSurgeonCheckedUncheckedUncheckedUncheckedUncheckedUncheckedUncheckedUncheckedUncheckedUncheckedUncheckedUncheckedUncheckedUncheckedUncheckedUncheckedUnchecked Complete911
1036Yes26APR2016YesCanton Mercy Medical Center Jane Westfall, RN, BSN, OSN                                Female     14JAN1981NoCheckedUncheckedUncheckedUncheckedUncheckedUncheckedSome college or 2-year degree$100,000 or moreMarriedWorking- as a paid employeeOHBreastStage 215MAY2016CheckedUncheckedUncheckedUncheckedUnchecked Yes, I am receiving hormone therapy.....0 No Concerns0 No Concerns0 No Concerns0 No Concerns0 No Concerns0 No Concerns0 No Concerns0 No Concerns0 No Concerns0 No Concerns0 No Concerns0 No Concerns0 No Concerns0 No Concerns0 No Concerns0 No Concerns0 (no concerns)0 (no concerns)0 (no concerns)0 (no concerns)0 (no concerns).0 (no concerns).0 (no concerns)0 (no concerns)0 (no concerns).0 (no concerns)0 (no concerns)0 (no concerns)0 (no concerns)0 (no concerns)0 (no concerns)0 (no concerns)0 (no concerns)3..5 Totally confident..5 Totally confident5 Totally confident4None1 time1 timeNoneNoneNoneNoneNoneNone CheckedUncheckedUncheckedUncheckedUncheckedUncheckedUncheckedUncheckedUncheckedUncheckedUncheckedUncheckedUncheckedUncheckedUncheckedUncheckedUnchecked Complete734
ballardw
Super User

And proc contents? Still betting that the date is actually a character variable.

 

By the way, you may want to rethink how you are reading the source data. That looks like proc import results from (likely) Excel.

 

The variables with names like There_are_many_reasons_people_d0 give that away.

Astounding
PROC Star

If that's not working, I would try:

 

dob = input(compress(Please_Enter_Your_Date_of_Birth), date9.);

 

 Also, the format that matches your original request would be:

 

format dob mmddyyd10.;

Tom
Super User Tom
Super User

Your posted code should not work at all as you cannot have two variables both named DOB. When you use a RENAME statement the variable does not have the new name until it is written.  Within the current data step you need to keep using the current name of the variable.

 

If you want to apply a new FORMAT to an existing variable ( Please_enter_your_date_of_birth_ ) and also rename it to DOB then your code should look like this.

 

data agemod;
  set Tmp1;
  rename Please_enter_your_date_of_birth_ = dob;
  format Please_enter_your_date_of_birth_ yymmdd10.;
run;

 

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