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

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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