BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Singla14
Calcite | Level 5
, 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
1 ACCEPTED SOLUTION

Accepted Solutions
andreas_lds
Jade | Level 19

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

5 REPLIES 5
PeterClemmensen
Tourmaline | Level 20

show us some code 🙂

RW9
Diamond | Level 26 RW9
Diamond | Level 26

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;
alexal
SAS Employee

@Singla14,

 

Something like this?

 

data years;
  input year;
datalines;
2013
2014
2015
2016
2017
;
run;
proc print data=years; where year=year(today()); run;
Singla14
Calcite | Level 5





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

andreas_lds
Jade | Level 19

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;

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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
  • 5 replies
  • 1007 views
  • 4 likes
  • 5 in conversation