DATA Step, Macro, Functions and more

how to import a year into sas

Accepted Solution Solved
Reply
Contributor
Posts: 52
Accepted Solution

how to import a year into sas

[ Edited ]

I am trying to import 'earliest_filing_year' and  'earliest_publn_year' from a .csv file into SAS by following codes.

    data SASDATA.TechnicalField ;

    infile 'R:/Li/PATSTAT/TechnicalField.csv' DLM = ',' DSD missover lrecl =32767 firstobs = 3 ;

    input appln_id :29. appln_auth :$29. appln_nr :$29. appln_kind :$29. appln_filing_date :YYMMDD10. appln_filing_year :YEAR10.

appln_nr_epodoc :$50. appln_nr_original :$150. ipr_type :$29. internat_appln_id :29. int_phase :$29. reg_phase :$29. nat_phase :$29.

earliest_filing_date :YYMMDD10. earliest_filing_year :yyyy. earliest_filing_id :29. earliest_publn_date :YYMMDD10. earliest_publn_year :yyyy.

earliest_pat_publn_id :29. granted :29. docdb_family_id :29. inpadoc_family_id :29. docdb_family_size :29. nb_citing_docdb_fam :29.

nb_applicants :29. nb_inventors :29.;

    format appln_filing_date :YYMMDDd10. appln_filing_year :YEAR10. earliest_filing_date :YYMMDDd10. earliest_filing_year :YEAR10.

earliest_publn_date :YYMMDDd10. earliest_publn_year :YEAR10. ;

    run ;

 

I try to use YEAR. and yyyy. to import the attribute but the log shows that

'ERROR 48-59: The informat YEAR was not found or could not be loaded.' and '

ERROR 48-59: The informat YYYY was not found or could not be loaded'

 

the domain of the attribute is a '4 digits in the form yyyy (e.g. 2015)

what should I do for it? thanks in advance.


Accepted Solutions
Solution
‎03-21-2018 12:48 PM
Super User
Posts: 10,532

Re: how to import a year into sas

A year on its own is just a number, so import it as that (without any informat).

The messages just tell you that such informats do not exist. (there is a format - note the missing "in" - year., but there is no format yyyy. at all).

Try these two statements:

input
  appln_id :29.
  appln_auth :$29.
  appln_nr :$29.
  appln_kind :$29.
  appln_filing_date :YYMMDD10.
  appln_filing_year :YEAR10.
  appln_nr_epodoc :$50.
  appln_nr_original :$150.
  ipr_type :$29.
  internat_appln_id :29.
  int_phase :$29.
  reg_phase :$29.
  nat_phase :$29.
  earliest_filing_date :YYMMDD10.
  earliest_filing_year
  earliest_filing_id :29.
  earliest_publn_date :YYMMDD10.
  earliest_publn_year
  earliest_pat_publn_id :29.
  granted :29.
  docdb_family_id :29.
  inpadoc_family_id :29.
  docdb_family_size :29.
  nb_citing_docdb_fam :29.
  nb_applicants :29.
  nb_inventors :29.
;
format
  appln_filing_date YYMMDDd10.
  appln_filing_year YEAR10.
  earliest_filing_date YYMMDDd10.
  earliest_publn_date :YYMMDDd10.
;
---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
How to convert datasets to data steps
How to post code

View solution in original post


All Replies
Solution
‎03-21-2018 12:48 PM
Super User
Posts: 10,532

Re: how to import a year into sas

A year on its own is just a number, so import it as that (without any informat).

The messages just tell you that such informats do not exist. (there is a format - note the missing "in" - year., but there is no format yyyy. at all).

Try these two statements:

input
  appln_id :29.
  appln_auth :$29.
  appln_nr :$29.
  appln_kind :$29.
  appln_filing_date :YYMMDD10.
  appln_filing_year :YEAR10.
  appln_nr_epodoc :$50.
  appln_nr_original :$150.
  ipr_type :$29.
  internat_appln_id :29.
  int_phase :$29.
  reg_phase :$29.
  nat_phase :$29.
  earliest_filing_date :YYMMDD10.
  earliest_filing_year
  earliest_filing_id :29.
  earliest_publn_date :YYMMDD10.
  earliest_publn_year
  earliest_pat_publn_id :29.
  granted :29.
  docdb_family_id :29.
  inpadoc_family_id :29.
  docdb_family_size :29.
  nb_citing_docdb_fam :29.
  nb_applicants :29.
  nb_inventors :29.
;
format
  appln_filing_date YYMMDDd10.
  appln_filing_year YEAR10.
  earliest_filing_date YYMMDDd10.
  earliest_publn_date :YYMMDDd10.
;
---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
How to convert datasets to data steps
How to post code
Super User
Posts: 13,898

Re: how to import a year into sas

Use of the YEAR format with value that only contains a year such as 2018 is going to yield incorrect results.

Please see:

data junk;
   year = 2018;
run;
proc print data=junk;
   var year;
   format year year4.;
run;

Which displays 1965 because a SAS date value is number of days from 1Jan1960 and 2,018 days from then is in 1965.

 

 

With values with only 4 digits you might want to use either F4. or best4. format.

☑ This topic is solved.

Need further help from the community? Please ask a new question.

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