BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Midi
Obsidian | Level 7

Hello Everyone , i'm trying to add a year column with the value 2016 for each observation , this is what i tried but it didn't work. 

Any Suggestion Would be Much Appreciated , thank you.

data DB_16; 
   set DB_16;
   format Year Year4.;
   Year = '2016'd;
run;

 

1 ACCEPTED SOLUTION

Accepted Solutions
Onizuka
Pyrite | Level 9

Why don't you try to just create a var with 2016 ?

 

data DB_16 ;
set DB_16 ;
year = 2016 ;
run ;

It will put 2016 on each observation

 

 

View solution in original post

5 REPLIES 5
novinosrin
Tourmaline | Level 20

Try

data DB_16; 
   set DB_16;
retain Year 2016;
  
run;
Midi
Obsidian | Level 7

Thank you , but that didn't work  !!!

PaigeMiller
Diamond | Level 26
data a;
    set a;
    year=2016;
run;

The reason your original code didn't work is that "2016"d is not valid, when you enclose a text string in quotes and append a D after the last quote, this indicates to SAS that the value enclosed in the quotes is a text date in the format of 01JAN16. and then SAS will convert it to a valid SAS date. But your code had "2016"d which is not a date in the proper format.

--
Paige Miller
Onizuka
Pyrite | Level 9

Why don't you try to just create a var with 2016 ?

 

data DB_16 ;
set DB_16 ;
year = 2016 ;
run ;

It will put 2016 on each observation

 

 

novinosrin
Tourmaline | Level 20

Please post the log

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 5 replies
  • 1850 views
  • 1 like
  • 4 in conversation