BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Jack1
Obsidian | Level 7

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

1 ACCEPTED SOLUTION

Accepted Solutions
PGStats
Opal | Level 21

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)

PG

View solution in original post

3 REPLIES 3
PGStats
Opal | Level 21

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,;

PG
Jack1
Obsidian | Level 7

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;

 

PGStats
Opal | Level 21

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)

PG

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 1286 views
  • 0 likes
  • 2 in conversation