Hello,
I am importing data from many csv files where the monthly date is entered as 2013m5 for May 2013, 2013m6 for June 2013 and so on. The letter m is between the year and the month.
What is the SAS date format I can use to read from the csv files the dates to be more like May2013, June2013 and so on?
Thanks
Jack
I would try:
data &NAICSbankrupt;
format TYPE $36. CODE $6. TITLE $46. theDate monyy7.;
infile "&outroot\&NAICSBankrupt..csv" dsd missover firstobs=13;
informat TYPE $36. DATE $7. CODE $6. TITLE $46. TITRE $46.;
input TYPE DATE CODE TITLE TITRE NL NS PEI NB QB ON MN SK AB BC NWT YK NU CA;
theDate = input(cats(translate(DATE, "-", "m"), "-1"), anydtdte.);
label Type = 'Type'
theDate = 'Date'
Code = 'NAICS'
Title = 'Title'
Titre = 'Titre'
NL = 'NL'
NS = 'NS'
PEI ='PEI'
NB = 'NB'
QB = 'QB'
ON = 'ON'
MN = 'MN'
SK = 'SK'
AB = 'AB'
BC = 'BC'
NWT ='NWT'
YK = 'YK'
NU = 'NU'
CA = 'CA';
drop Titre DATE;
run;
(untested)
You could read the dates as character strings (length>=7) and translate to SAS dates with something like:
date = input(cats(translate(dateStr, "-", "m"), "-1"), anydtdte.);
format date monyy7,;
Thanks.
I inserted the code you provided but I couldn't get it to produce the dates correctly. Here is my code -- where would I insert your recommeded coding?
Thanks...
data &NAICSbankrupt;
format TYPE $36. DATE $7. CODE $6. TITLE $46. TITRE $46. NL NS PEI NB QB ON MN SK AB BC NWT YK NU CA;
infile "&outroot\&NAICSBankrupt..csv" dsd missover firstobs=13 obs=2234;
informat TYPE $36. DATE $7. CODE $6. TITLE $46. TITRE $46. NL NS PEI NB QB ON MN SK AB BC NWT YK NU CA;
input TYPE DATE CODE TITLE TITRE NL NS PEI NB QB ON MN SK AB BC NWT YK NU CA;
label Type = 'Type'
Date = 'Date'
Code = 'NAICS'
Title = 'Title'
Titre = 'Titre'
NL = 'NL'
NS = 'NS'
PEI ='PEI'
NB = 'NB'
QB = 'QB'
ON = 'ON'
MN = 'MN'
SK = 'SK'
AB = 'AB'
BC = 'BC'
NWT ='NWT'
YK = 'YK'
NU = 'NU'
CA = 'CA';
drop Titre;
run;
I would try:
data &NAICSbankrupt;
format TYPE $36. CODE $6. TITLE $46. theDate monyy7.;
infile "&outroot\&NAICSBankrupt..csv" dsd missover firstobs=13;
informat TYPE $36. DATE $7. CODE $6. TITLE $46. TITRE $46.;
input TYPE DATE CODE TITLE TITRE NL NS PEI NB QB ON MN SK AB BC NWT YK NU CA;
theDate = input(cats(translate(DATE, "-", "m"), "-1"), anydtdte.);
label Type = 'Type'
theDate = 'Date'
Code = 'NAICS'
Title = 'Title'
Titre = 'Titre'
NL = 'NL'
NS = 'NS'
PEI ='PEI'
NB = 'NB'
QB = 'QB'
ON = 'ON'
MN = 'MN'
SK = 'SK'
AB = 'AB'
BC = 'BC'
NWT ='NWT'
YK = 'YK'
NU = 'NU'
CA = 'CA';
drop Titre DATE;
run;
(untested)
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.