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-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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