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

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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
  • 1397 views
  • 1 like
  • 4 in conversation