DATA Step, Macro, Functions and more

Sas year comparision

Accepted Solution Solved
Reply
New Contributor
Posts: 4
Accepted Solution

Sas year comparision

, I have input file having year ( let's say 2015 to 2017 YYYY) .
I am trying to fetch system year ( year(today())
And then compare year from input file to fetched year.
If matches , those rows should come in output.

If comparison for years is not working ..Have tried reading input year in chat..Integer both..But nothing working.
Can some one please help..Urgent

Accepted Solutions
Solution
‎09-12-2017 05:09 AM
Valued Guide
Posts: 519

Re: Sas year comparision

I suggest you start reading the SAS documentation, because your code has so many errors resulting from missing knowledge.

 

  1. You don't need INFLE1, you can use the functions directly when createding infle2.
  2. A SET statement with multiple datasets appends the datasets.
  3. Using a format designed for variables containing dates on a variable containing just the year-part of a date, will lead to wrong results. You don't need formats to solve the problem.
data INFLE2;
infile DD01;
input 
     @36 YearX 4.
     @1 Record  $char150.;

   if YearX = year(today());
run;

View solution in original post


All Replies
PROC Star
Posts: 1,215

Re: Sas year comparision

show us some code Smiley Happy

Super User
Super User
Posts: 9,416

Re: Sas year comparision

Show us some code and show us some test data data in the form of a datastep.  

E.g.:

data have;
  input year;
datalines;
2013
2017
;
run;
SAS Employee
Posts: 512

Re: Sas year comparision

@Singla14,

 

Something like this?

 

data years;
  input year;
datalines;
2013
2014
2015
2016
2017
;
run;
proc print data=years; where year=year(today()); run;
New Contributor
Posts: 4

Re: Sas year comparision

[ Edited ]





Input file is of 150.. Year is starting at 36th.. A0214494 FLDNIW0000414600DRIN 201401010.... A0214494 FLDNIW0000104200CRIN 201401010.. A0330094 FLDQIW0000104200CRSD 201401010.. SAS code: DATA INFLE1; DATERUN = TODAY(); FINAL_YEAR=YEAR(DATERUN); FORMAT FINAL_YEAR YEAR4. ; RUN ; PROC PRINT DATA=INFLE1; DATA INFLE2; INFILE DD01; INPUT @36 YEARX 4. @1 RECORD $CHAR150.; FORMAT YEARX YEAR4.; RUN; PROC PRINT DATA=INFLE2; DATA OUTP1; SET INFLE1 INFLE2; IF YEARX = FINAL_YEAR THEN OUTPUT OUTP1 ; RUN; DATA FINAL1; SET OUTP1 ; FILE DD01O; PUT @1 RECORD $CHAR150.; RUN;

 YEARX = FINAL_YEAR is not working ... i have tried other formatting options too... like took input year in Char as well.. but 0 records in output..

I think issue is ..sas 's internal format.. 2017 would mean..1965 when i am moving it into YEAR4....

Solution
‎09-12-2017 05:09 AM
Valued Guide
Posts: 519

Re: Sas year comparision

I suggest you start reading the SAS documentation, because your code has so many errors resulting from missing knowledge.

 

  1. You don't need INFLE1, you can use the functions directly when createding infle2.
  2. A SET statement with multiple datasets appends the datasets.
  3. Using a format designed for variables containing dates on a variable containing just the year-part of a date, will lead to wrong results. You don't need formats to solve the problem.
data INFLE2;
infile DD01;
input 
     @36 YearX 4.
     @1 Record  $char150.;

   if YearX = year(today());
run;
☑ This topic is solved.

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

Discussion stats
  • 5 replies
  • 197 views
  • 4 likes
  • 5 in conversation