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
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;
What is the purpose of renaming marks to _2017_marks?
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 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.