BookmarkSubscribeRSS Feed
sanjay1
Obsidian | Level 7

Hi SAS experts,

 

I want to add new variables into the dataset.

 

data new;
input name$ marks year;
datalines;
abc 10 2015
ab 20 2016
ba 30 2017
ca 10 2015
bv 20 2016
ka 20 2017
;
run;

 

i want to  add 3 variables in new data set
1.marks_1 = marks * 150
2.marks_2 = marks * 250
3.marks_3 = marks * 350

 

for example:
name _2017_MARKS MARKS_1 MARKS_2 MARKS_3
ba   30         4500     7500    10500
ka   20         3000     5000      7000

 

Similarly for 2015,2016 also. please guide.

 

Thanks & regards,

Sanjay

3 REPLIES 3
PeterClemmensen
Tourmaline | Level 20

like this?

 

data new;
input name$ marks year;
datalines;
abc 10 2015
ab 20 2016
ba 30 2017
ca 10 2015
bv 20 2016
ka 20 2017
;

data new;
   set new;
   marks_1 = marks * 150;
   marks_2 = marks * 250;
   marks_3 = marks * 350;
run;
RW9
Diamond | Level 26 RW9
Diamond | Level 26

Tip, don't put "data" into column names or dataset names, use simple naming conventions like <prefix><incrementor> so that you can easily refer to variables and groups of variables using inbuilt SAS commands like:

VAR1 VAR2 VAR3, can be VAR:, or VAR1--VAR3, or array VAR{3}

Putting data in coumns names/dataset names really just overcomplicates your coding time and effort, and makes unmanageable code.  Note, this doesn't apply to Labels, put whatever you like in them.

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
  • 3 replies
  • 866 views
  • 0 likes
  • 4 in conversation