Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I would suggest changing the variable format instead. Using put/input may cause incorrect results when the variable format is not changed. For example, if you change dates to years using put/input, but leave the variable format as date9, then the dates will still be read as date9 (the underlying value will be year). If you export to CSV the dates will be incorrect.</p> <p>Here's a simple macro that will check all variables and isolate the dates in order to modify their format to year. You would need to specify which date formats could be in your dataset (or create a more exhaustive list than what is in the macro), and modify it to produce the data format you need.</p> <pre><code>%macro _toyear(dsin=,dsout=); /* proc contents will list all variables in the dataset, with formats */ proc contents data=&amp;dsin out=_contents noprint; run; data _contents; set _contents (where=(format in: ("DATE", "MMDDYY", "MMYY"))); run; /* use proc sql to create a macro variable with a list of the date variables */ proc sql noprint; selet name into: datevars separated by " " from _contents; quit; /* simple error checking, in case there are no date variables */ %let dsid = %sysfunc(open(_contents, is)); %let nlobs = %sysfunc(attrn(&amp;dsid, nlobs)); /* output dataset */ data &amp;dsout; set &amp;dsin; %if &amp;nlobs ne 0 %then %do; format &amp;datevars year4.; %end; run; /* clean-up */ %let rc = %sysfunc(close(&amp;dsid)); proc datasets nolist; delete _contents; run; %mend _toyear; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload