NotesWhat is notes.io?

Notes brand slogan

Notes - notes.io

/* SQL in SAS */
data class;
set sashelp.class;
run;

proc sql;
create table class1 as
select * from sas.help.class;
quit;
/*subsetting*/
data class2;
set class;
keep name age;
run;

proc sql;
create table class2sql as
select name age from sas.help.class;
quit;

/* print the dataset*/
options obs=5;
proc print data = sashelp.class;
quit;

/*to know the contents*/
proc sql;
describe table sashelp.class;
quit;

/*print the dataset with filter*/
proc sql;
select * from sashelp.class
where sex='M';
run;

/* to add variable*/
proc sql;
create table class2 as
select age as AGE1, name as name1, "student data" as dataset from sashelp.class;
quit;


data class2a;
set sashelp.class;
rename age=age1 name=name1;
dataset="student data";
keep age name dataset;
run;

/* applying format, specifying length and labling*/

proc format ;
value agect 0-15 ="0-15"
16-30 = "16-30"
;
quit;

data class3;
set sashelp.class;
age_ct = age;
length age_ct 7;
label age_ct = "Age Category"
format age_ct agect.;
run;


proc sql ;
create table class3sql as
select name,age,sex as gender,height,weight,age as age_ct length=7 format=agect. label"Age Category" from sashelp.class
where height <=65;
quit;

/*to sort the dataset*/
proc sql;
create table class4 as
select * from sashelp.class
order by sex desc;
quit;

proc sort data=sashelp.class out=class4a (keep=name sex);
by descending sex;
run;

/*removing the duplicates*/
proc sort data=sashelp.class out=class5 nodupkey;
by sex;
run;

proc sql;
create table class5a as
select distinct(sex) as gender from sashelp.class; *Distinct: to remove duplicate observation;
quit;

proc sql;
create table class5a as
select distinct(sex) as gender,name,height,weight from sashelp.class /*Distinct: to remove duplicate observation*/
order by gender;
quit;


/*group by having*/
proc sql;
select * from sashelp.classfit;
quit;

proc sql;
create table data1 as
select count(name) as count,name,sex,lowermean,uppermean from sashelp.classfit
where uppermean>10
group by sex
having lowermean >=70;
quit;

/*ususal method for the above step which is very lengthy*/
proc means data = sashelp.classfit;
class sex;
output out=cnt (where=(_STAT_="N" and sex~="") keep=sex _freq_ _stat_);
run;

proc sort data=cnt (drop=_stat_); by sex; run;
proc sort data=sashelp.classfit out=class6; by sex ; run;

data class7 (where = (uppermean > 10));
merge cnt (in=a) class6 (in=b);
by sex;
rename _freq = count;
run;

/*inserting values in a dataset*/
data data1;
set sashelp.class;
run;

data add;
Name = "Student-1";
age= 16;
sex="F";
height=60;
weight=50; output;
run;

data data2;
length name $10.;
set class add;
run;

proc sql;
create table data as
select name length =10, sex, age, height, weight from sashelp.class;
insert into data
values ("student-1","F",16,60,50)
values ("student-2","F",16,80,70);
quit;

/*recode into different variables*/
data data7;
set sashelp.class;
length genfer $10.;
if sex="M" then gender="Male";
else if sex="F" then gender="Female";
run;


proc sql;
create table data7a as
select name, sex, age,height,weight,
case
when sex="M" then "Male"
when sex="F" then "Female"
end as gender
from sashelp.class;
quit;

/* some errors from here*/
/* calculating the new variable*/
data data1;
set sashelp.class;
weight_dummy = 0.5 * weight;
name_gender = compress(Name) || "/" || compress(sex);
run;

proc sql;
create table data1b as
select name, age, sex, weight, 0.5*weight as weight_dummy, compress(Name) || "/" || compress(sex) as name_gender from sashelp.calss;
quit;

/*calculating the summmary statistics using SAS sql*/
proc sql;
create table summary as
select 'Age' as Var, sex as gender, mean(age) as mean format=5.2 label="Mean Age", std(age) as sd format=6.3, min(age) as min, max(age) as max, from sashelp.class;
group by sex;
quit;


proc means data=sashelp.class nway;
class sex;
var age;
output out=means(drop=_:) n=n mean=mean std=sd min=min max=max;
run;

proc sql;
create table total as
select count(name) as cnt from sashelp.class;
quit;


proc sql;
select count(name) into: cnt from sashelp.class;
quit;
%put & cnt;

proc sql;
create table summary1 as
select count(name) as n, (count(name)/&cnt)*100 as pct, sex from sashelp.class
group by sex;
quit;

proc freq data=sashelp.class;
tables sex/out=freq;
run;

proc sql;
create table summary2 as
select count(age) as n,mean(age) as mean, std(age) as SD, min(age) as min, median(age) as median, max(age) as max,
stderr(age) as stderr from sashelp.class
where sex="F"
group by sex;
quit;

/*dataset merging*/

data data1;
length name $25. place $20;
name = "jo"; place="udupi"; output;
name = "ram" ; place="mangalore"; output;
name = "hai" ; place="parkala"; output;
run;

data data2;
length name $25. place $20;
name = "jo"; company="web"; output;
name = "hello" ; company="world"; output;
name = "hai" ; company="micro"; output;
run;

proc sort data=data1; by name; run;
proc sort data=data2; by name; run;

/*condition 1 ; to get the data for common subjects;*/
data merge1;
merge data1 (in=a) data2 (in=b);
by name;
if a and b;
run;

/*condition 2 ; to get the data for all the subjects;*/
data merge1;
merge data1 (in=a) data2 (in=b);
by name;
if a or b;
run;


/*condition 3 ; to get the data for all the subjects in data1;*/
data merge1;
merge data1 (in=a) data2 (in=b);
by name;
if a ;
run;


/*condition 4 ; to get the data for all the subjects in data2;*/
data merge1;
merge data1 (in=a) data2 (in=b);
by name;
if b;
run;

/*using proc sql*/
proc sql noprint;
create table sql1 as
select * from data1 as a left join data2 as b
on a.name = b.name;
quit;

proc sql noprint;
create table sql2 as
select * from data1 as a right join data2 as b
on a.name = b.name;
quit;

/*combining 2 datesets*/
data data3;
set data1 data2;
run;

proc sql;
create table data3a as
select name, place from data1 union
select name,company from data2;
quit;





/*DATEPART and TIMEPART*/

data abc;
date = datetime();
date1 = datepart(date); /*To retrieve the date part from the date time variable*/
time1 = timepart(date); /*To retrieve the time part from the date time variable*/
date2 = datepart(date);
date3 = datepart(date);
format date datetime19. date1 date9. date2 ddmmyy8. time1 timeampm8. date3 ddmmyy10.;
run;






/* importing data from an excel sheet in sas */
proc import out=pharma
datafile="/home/u59124642/Sample/PharmaDemo.xls"
dbms = xls replace;
run;

data data2;
infile "/home/u59124642/nutrient (1).txt";
input Slno $ VitA $ VitB $ VitC $ VitD;
drop Slno;
run;

/* To create a data set */
data data3;
input patient $ height;
cards;
patient1 109
patient2 89
patient3 92
;
run;

data cars;
set sashelp.cars;
if make = "Acura";
run;

data cars1;
set sashelp.cars;
where make = "Acura";
run;

proc means data= sashelp.cars;
where make = "Acura";
var Invoice;
run;

data data1;
set cars1;
engine = enginesize * 10;
keep engine enginesize;
where engine < 25;
run;

data data1;
set cars1;
engine = enginesize * 10;
keep engine enginesize;
if engine < 25;
run;

data data2;
set sashelp.class;
/* where height in (62.5,72,67); */
/* where height lt 62.5; */
/* where height gt 62.5; */
/* where height not eq 62.5; */
/* where sex~="M"; */
/* where sex not eq "M"; */
where name in ("Alice","Joyce");
run;

data class;
set sashelp.class;
keep name age;
run;

proc sort data=class;
by age;
run;

data data3;
set class;
by age;
if first.age then seq = 1;
else seq+1;
if first.age;
run;

data data3;
set class;
by age;
if first.age then seq = 1;
else seq+1;
if last.age;
run;







/* importing data from an excel sheet in sas */
proc import out=pharma
datafile="/home/u59124642/Sample/PharmaDemo.xls"
dbms = xls replace;
run;

data data2;
infile "/home/u59124642/nutrient (1).txt";
input Slno $ VitA $ VitB $ VitC $ VitD;
drop Slno;
run;

/* To create a data set */
data data3;
input patient $ height;
cards;
patient1 109
patient2 89
patient3 92
;
run;

data cars;
set sashelp.cars;
if make = "Acura";
run;

data cars1;
set sashelp.cars;
where make = "Acura";
run;

proc means data= sashelp.cars;
where make = "Acura";
var Invoice;
run;

data data1;
set cars1;
engine = enginesize * 10;
keep engine enginesize;
where engine < 25;
run;

data data1;
set cars1;
engine = enginesize * 10;
keep engine enginesize;
if engine < 25;
run;

data data2;
set sashelp.class;
/* where height in (62.5,72,67); */
/* where height lt 62.5; */
/* where height gt 62.5; */
/* where height not eq 62.5; */
/* where sex~="M"; */
/* where sex not eq "M"; */
where name in ("Alice","Joyce");
run;

data class;
set sashelp.class;
keep name age;
run;

proc sort data=class;
by age;
run;

data data3;
set class;
by age;
if first.age then seq = 1;
else seq+1;
if first.age;
run;

data data3;
set class;
by age;
if first.age then seq = 1;
else seq+1;
if last.age;
run;






libname mahe '/home/u59124642/Sample';

data ph;
set mahe.ph;
run;

/*summarizing a continuous variable*/

proc means data=ph n q1 q3 median lclm uclm min max;
var height;
run;

proc means data=ph;*n q1 q3 median lclm uclm min max;
var height;
output out = summary;
run;

proc means data=ph n mean std q1 q3 median lclm uclm min max;
var height;
output out=summary n=n q1=q1 q3=q3 median=median mean=average std=SD lclm=lower uclm=upper min=minimum max=maximum;
run;

data summary1;
set summary;
N_char = strip(put(n,5.));
mean_sd= strip(put(average,5.1)) || " ("||strip(put(SD,5.2))||")";
median_q1_q3 = strip(put(median,5.1)) || " ("||strip(put(q1,5.1))||","||strip(put(q3,5.1))||")";
min_max = "("||strip(put(minimum,5.))||", "||strip(put(maximum,5.))||")";
run;

proc transpose data=summary1 out=summary2 (rename=(_name_=Statistic col1=Value));
*by;
*id;
var N_char mean_sd median_q1_q3 min_max;
run;

data summary3;
length Statistic $20.;
set summary2;
if Statistic='Nchar' then Statistic='N';
else if Statistic='mean_sd' then Statistic='Mean (SD)';
else if Statistic='median_q1_q3' then Statistic='Median (Q1,Q3)';
else if Statistic='min_max' then Statistic='Min,Max';
run;

proc sort data=ph;
by gender;
run;

proc means data=ph n mean std q1 q3 median lclm uclm min max;
var height;
by gender;
output out=summary n=n q1=q1 q3=q3 median=median mean=average std=SD lclm=lower uclm=upper min=minimum max=maximum;
run;

proc means data=ph noprint n mean std q1 q3 median lclm uclm min max;
var height;
by gender;
output out=summary n=n q1=q1 q3=q3 median=median mean=average std=SD lclm=lower uclm=upper min=minimum max=maximum;
run;

data summary4;
set summary;
N_char = strip(put(n,5.));
mean_sd= strip(put(average,5.1)) || " ("||strip(put(SD,5.2))||")";
median_q1_q3 = strip(put(median,5.1)) || " ("||strip(put(q1,5.1))||","||strip(put(q3,5.1))||")";
min_max = "("||strip(put(minimum,5.))||", "||strip(put(maximum,5.))||")";
run;

proc transpose data=summary4 out=summary5 (rename=(_NAME_=Statistic));
*by;
id Gender;
var N_char mean_sd median_q1_q3 min_max;
run;

data summary6;
length Statistic $20.;
set summary5;
if Statistic='N_char' then Statistic='N';
else if Statistic='mean_sd' then Statistic='Mean (SD)';
else if Statistic='median_q1_q3' then Statistic='Median (Q1,Q3)';
else if Statistic='min_max' then Statistic='Min,Max';
run;

ods trace on;

proc ttest data=ph;
var height;
class gender;
ods output TTests = pval;
run;

ods trace off;

data pval1;
set pval;
if Variances='Equal';
Statistic = 'N';
keep probt Statistic;
run;

proc sort data=summary6;
by statistic;
run;

data combine;
merge summary6 pval1;
by statistic;
if Statistic = 'Mean (SD)' then order=2;
else if Statistic = 'N' then order=1;
else if Statistic = 'Median (Q1,Q3)' then order=3;
else if Statistic = 'Min,Max' then order=4;
run;

proc sort data=combine;
by order;
run;

data combine2;
set combine;
drop order;
run;

/*Indicating missing values*/

/*To view info of the dataset*/
proc contents data=ph;
run;

proc univariate data=ph;
var height;
run;

/* To add normality data */
proc univariate data=ph normal;
var height;
run;

/* To add histogram */

proc univariate data=ph normal;
var height;
histogram height/normal;
run;

/* Seperating by gender */
proc univariate data=ph normal;
var height;
histogram height/normal;
by gender;
run;

/*proc freq: For obtaining counts and percentages*/

proc freq data=ph;
tables gender;
run;

ods trace on;
proc freq data=ph;
tables gender;
ods output OneWayFreqs=freq;
run;
ods trace off;

/*or*/

proc freq data=ph;
tables gender/out=freq;
run;

proc freq data=ph;
tables center_id*gender/out=freq (drop=Percent);
run;

proc freq data=ph;
tables center_id*gender/out=freq (drop=Percent);
tables center_id/out=total(rename=(count=total) drop=Percent);
run;

data freq2;
merge freq total;
by center_id;
run;

proc freq data=ph;
tables center_id*gender/chisq fisher;
run;

data mahe.summary;
set summary6;
run;

data mahe.summary2;
set summary3;
run;

/* Non parametric analog one independent sample t test (Mann Whitney U test) */

proc npar1way data=ph;
class gender;
var height;
run;














ods trace on;
ods output summary = desc;
proc means data=sashelp.class;
class sex;
var height;
run;
ods trace off;

data desc1;
set desc;
drop nobs;
run;

/*Proc Report*/
/*1. To Create the structured format of output in PDF, RTF, HTML or even in Excel format;*/

ods pdf file="/home/u59124642/Sample/report1_demonstration.pdf"; /*Change pdf to html,rtf,excel,csv to change format*/
proc report data=desc1;
column sex height_N height_mean height_stddev; /*Required variables included in the report*/
define sex/"Gender"; /*renaming the variables in the report*/
define height_N/"Count";
define height_mean/"Average"format=5.2;
define height_stddev/"SD"format=6.3;
title1 "Summary Statistics for Class dataset";
title2 "(Demonstrated by Aditya)";
footnote1 "This demonstration is for learning purpose.";
footnote2 "Date: 9th October 2021";
run;
ods pdf close;/*Change pdf to html,rtf,excel,csv change format*/

/*Example 2*/
proc print data= sashelp.class;
run;

/* Output displayed as sum */
proc report data=sashelp.class;
column height weight;
define height/"Height (in cm)";
define weight/"Weight (in kg)";
run;

/*Display: To list values as they appear in data */
proc report data=sashelp.class;
column height weight;
define height/"Height (in cm)" display;
define weight/"Weight (in kg)" display;
run;

/* Grouping observations based on gender */
proc report data=sashelp.class;
column sex height weight;
define sex/"Gender" group;
define height/"Height (in cm)" display;
define weight/"Weight (in kg)" display;
run;

/* Can use center, right, left for alignment in the report */
proc report data=sashelp.class;
column sex weight;
define sex/"Gender" group;
define weight/"Weight (in kg)" display center;
run;

/*Display display is to list the values as they appear in the data*/
/*Group is to group the variable*/
/* Order arranges according to a particular sequence */
proc report data=sashelp.class;
column sex weight;
define sex/"Gender" group;
define weight/"Weight (in kg)" display right order;
run;

/*Example 4*/
proc sort data=sashelp.class out=data1;
by sex;
run;

ods pdf file="/home/u59124642/Sample/report2_demonstration.pdf";
proc report data=data1;
by sex; /*To split the report by gender in separate pages*/
column height weight;
define height/"Height (in cm)" display;
define weight/"Weight (in kg)" display format=5.0;
run;
ods pdf close;

/*Example 5*/

proc print data=sashelp.fish;
run;

/* Compute:Creating new variable in report */
proc report data=sashelp.fish;
column species length1 length2 length3 length_mean weight;
define species/"species" group;
define weight/"weight";
define length1/"lenght-1" order;
define length2/"lenght-2" order;
define length3/"lenght-3" order;
define length_mean/"Average" computed;
compute length_mean;
length_mean=mean(length1,length2,length3);
endcomp;
run;

/*Example 6*/
proc report data=sashelp.class;
column sex name age height weight;
define sex/"Gender" group;
define name/"Name of the student";
define height/"Height in cm";
define weight/"Weight in kg";
compute after sex;
line " ";
endcomp;
run;

/*Example 7*/
/* For getting footnote at the end of the table and not at end of the page */
*ods pdf file="report2.pdf";
proc report data=sashelp.class;
column sex name age height weight;
define sex/"Gender" group;
define name/"Name of the student";
define height/"Height in cm";
define weight/"Weight in kg";
compute after/style=[just=left];
line "This demonstration is for learning purpose";
line "09 October 2021";
line "Conducting for Department data Science Batch-2021";
endcomp;
run;
*ods pdf close;

/*Example 8*/

proc format;
value $gender "M"="Male"
"F"="Female"
;
run;

proc report data=sashelp.class;
column sex name age height weight;
define sex/"Gender" group noprint;
define name/"Name of the student";
define height/"Height in cm";
define weight/"Weight in kg";
compute before sex/style=[just=left];
line "Gender:" sex $gender.;
endcomp;
run;

/*Example9: To get the figures in the procedure*/
ods graphics on;
proc ttest data=sashelp.class;
class sex;
var height;
run;
ods graphics off;

/*Example 10*/
proc report data= sashelp.class;
columns sex name age height weight;
define name/"Name" display width=10; /*width of 10 chars*/
define sex/"Gender" group width=6;
define age/"Age" display width=5;
define height/"Height" analysis mean format=5.2; /*Contributes values to a calculation or statistic*/
define weight/"Weight" analysis mean format=5.2;
break after sex/ summarize suppress; /*Summarize:Writes summary lines in each group of break lines*/
run;

/*Important Question*/

proc print data=sashelp.birthwgt;
run;

ods trace on;
ods output CrossTabFreqs = Freq1;
proc freq data=sashelp.birthwgt;
tables married*lowbirthwgt /norow nopercent;
run;
ods trace off;

ods output CrossTabFreqs = Freq1;
proc freq data=sashelp.birthwgt;
tables married*lowbirthwgt /norow nopercent;
run;

ods output CrossTabFreqs = Freq2;
proc freq data=sashelp.birthwgt;
tables race*lowbirthwgt /norow nopercent;
run;

ods output CrossTabFreqs = Freq3;
proc freq data=sashelp.birthwgt;
tables death*lowbirthwgt /norow nopercent;
run;

data freq1a(keep= cat lowbirthwgt col_pct var);
set freq1;
length var cat $30.;
if married~="" and lowbirthwgt~="";
col_PCT = strip(put(frequency,best.))||" ("||strip(put(round(colpercent,0.01),best.))||")";
var = "Marital Status";
cat = married;
run;

data freq2a(keep= cat lowbirthwgt col_pct var);
set freq2;
length var cat $30.;
if race~="" and lowbirthwgt~="";
col_PCT = strip(put(frequency,best.))||" ("||strip(put(round(colpercent,0.01),best.))||")";
var = "Race";
cat = race;
run;

data freq3a(keep= cat lowbirthwgt col_pct var);
set freq3;
length var cat $30.;
if death~="" and lowbirthwgt~="";
col_PCT = strip(put(frequency,best.))||" ("||strip(put(round(colpercent,0.01),best.))||")";
var = "Death";
cat = death;
run;

data freq_comb;
set freq1a freq2a freq3a;
run;

proc sort data=freq_comb;
by var cat;
run;

proc transpose data=freq_comb out=freq4 (drop=_NAME_);
id lowbirthwgt;
by var cat;
var col_pct;
run;

proc format;
value $cat "Death" = "Death"
"Race" = "Race"
"Marital Status" = "Marital Status"
;
run;
/* Applying proc report */

ods pdf file="/home/u59124642/Sample/birthwgt_report.pdf";
proc report data=freq4 (rename=(var=var1));
column var1 cat ("Low Birth Weight" (yes no));
define var1/"" noprint group;
define cat/"" format=$cat.;
define yes/"Yes";
define no/"No";
compute before var1/ style =[just = left];
line "Category:" var1 $cat.;
endcomp;
compute after/style=[just = left];
line "The report is generated for practise purposes";
line "Date: 09 October 2021";
endcomp;
title "Summary of Low Birth Weight ";
run;
ods pdf close;












/*SAS MACRO*/


%MACRO TYPE_SUMMARY_AUTOMATION(car_type);
proc sql;
create table &car_type._summary as
select type
,origin
,count(*) as no_of_units
,sum(msrp) as total_msrp
,sum(invoice) as total_invoive
from sashelp.cars
where upcase(type)="&car_type."
group by 1,2;
quit;
proc print data=work.&car_type._summary;
run;

%MEND;

%type_summary_automation(SUV);

/*%let -define a macro variable*/

%let first_number=773;
%let second_variable=276;

%put &first_number.;

data testing;
sum= &first_number. + &second_variable.;
run;

/*LOCAL-macro variables defined inside a macro.these can be used only in the same macro where it has
been created*/

PROC PRINT data=sashelp.class noobs;
title "class dataset";
run;

/*objective is to create a summmary table for height weight age by gender*/

/* descriptive stats by height*/
proc means data=sashelp.class n q1 q3 mean max min median ;
class sex;
var height;
run;

/* descriptive stats by weight*/
proc means data=sashelp.class n q1 q3 mean max min median ;
class sex;
var weight;
run;

/* descriptive stats by age*/
proc means data=sashelp.class n q1 q3 mean max min median ;
class sex;
var age;
run;

/* using sas macro*/
%macro summary(var);
proc means data=sashelp.class n q1 q3 median max min mean;
class sex;
var &var.;

%mend;

%summary(age);
%summary(weight);
%summary(height);

/*y use sas macro
1. it will be used for repetitive task and it will reduce programming time*/

/*introduction to sas macro*/
/* using caars dataset*/

proc print data=sashelp.cars;
run;
/* horse power by make
horse power by type*/

%macro summary_cars(a,b);
proc means data=sashelp.cars min max q1 q3 median mean;
class &b.;
var &a.;
%mend;
%summary_cars(Horsepower,Type);
%summary_cars(Horsepower,Make);
/* common errors
1. improper macro name
2.position of macro variable
3.forgetting to add mend*/

/*to perform independent sample ttest*/
ODS TRACE ON;
proc ttest data=sashelp.cars;
class type;
var length;
where type in ("SUV" "Sedan");
ods output ConfLimits=CI;
RUN;
ODS TRACE OFF;

/*to perform independent sample ttest using macro*/
option mlogic mprint merror
%macro ttest(a,b);
proc ttest data=sashelp.cars;
class type;
var &a.;
where type in ('SUV' 'Sedan');
ods output ConfLimits=&b.;
%mend;

%ttest(horsepower,CI);

data data1;
set sashelp.cars;
keep horsepower length;
run;

data data2;
set sashelp.class;
keep name age;
run;


%macro keep (input,output,var1,var2);
data &output;
set sashelp.&input;
keep &var1 &var2;
run;
%mend;

%keep (input=cars,output=data4,var1=horsepower,var2=length);


/* macro variable*/
/* %let
macro parameter
sas sql*/

%let text="my name is jagriti";
%let daytime= "30-1-2021";
%let com="hii";
%put &text;

data dummy1;
text=&text;
daytime=&daytime;
comment=&com;
run;


proc sql;
select mean(height) as mn_height format=5.2 label='mean_height' from sashelp.class;
quit;

/*assign macro variable using proc sql*/

proc sql;
select mean(height) into: mn_height from sashelp.class;
quit;

%put &mn_height;

/* call symput*/

proc means data=sashelp.cars nway;
class type;
var horsepower;
output out=dummy;
run;

data dummy1;
set dummy;
where type='Sedan' and _STAT_="MEAN";
CALL symput ("mn_hp",horsepower);
call symput ("Mean_hp",_STAT_);
run;
%put &mn_hp;
DATA dummy2;
summary= "&Mean_hp";
val= &mn_hp;
run;

%put _all_;/*list all macro variable*/

/*sas macro function*/
%let a=15;
%let b=30;


data a2;
a=&a;
b=&b;
run;

data a2;
a=&a;
b=&b;
c=&a * &b;
run;

%let a=15;
%let b=30;
%put &a;
%let c= &a*&b;
%put &c; /*its not giving 450*/

/* to get calculated value*/
%let a=15;
%let b=30;
%put &a;
%let c= (&a*&b);
%let c1= %eval(&a*&b);
%put &c;
%put &c1;

/*sysfunction*/
%let date =%sysfunc(date(),date9.);
%put &date;

/*eval vs syseval*/
%let a=7.2;
%let b=11.2;
%let c=&a+&b;
%put &c;
/*this will throw a error because of decimal*/
%let c1=%eval(&a+&b);
%put &c1;

/* sysevalf*/
%let a=7.2;
%let b=11.2;
%let c=&a+&b;
%put &c;
/*this will throw a error because its float number*/
%let c1=%sysevalf(&a+&b);
%put &c1;



data demog;
set sashelp.demographics;
run;

proc print data=demog noobs;
run;

OPTION MERROR MPRINT MLOGIC SYMBOLGEN;
proc means data=demog;
class region;
var pop;
where name="SAINT KITTS/NEVIS";
title1 "summary report for SAINT KITTS/NEVIS";
run;

OPTION MPRINT
%macro mean (a);
proc means data=demog;
class region;
var pop;
where name="&a";
title1 "summary report for &a";
run;
%mend;

%mean(a=SAINT KITTS/NEVIS);
%mean(a=DOMINICAN REPUBLIC);
%mean(a=PERU);

/* & vs && vs &&&:internet example*/
%let x=temp;
%let n=3;
%let x3=results;
%let temp3=results2;

%put &x&n; /*macro variable X resolves in temp and n in 3 result as temp3*/
%put &&x&n; /* 2 &&x-->&x and &n-->3 which will give us &x3-->result*/
%put &&&x&n;/*first 2 && in single & and third &and x -->temp and &n-->3 which will give us &temp3-->result2*/


proc print data= demog;
run;

proc sql noprint;
create table region as /*creating the dataset called region*/
select distinct region from demog;
select count(distinct region) into: cnt from demog;
quit;

%put &cnt;

data a1;
set region;
concat =catt("region",_n_);
run;

data _null_;
set region;
call symput (catt("region",_n_),region);
run;

%put &region1;
%put &region2;
%put &region3;
%put &region4;
%put &region5;
%put &region6;

proc means data =demog nway nonobs n mean ndec=2;
where region='AFR';
class ISONAME;
var AdultLiteracypct;
title "Report 1";
run;

option mprint mlogic;
%macro GG;
%do i=1 %to 5;
proc means data =demog nway nonobs n mean ndec=2;
where region='&&region&i';
class ISONAME;
var AdultLiteracypct;
title "Report &i : &&region&i";
run;
%end;
%mend;
%GG;


     
 
what is notes.io
 

Notes.io is a web-based application for taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000 notes created and continuing...

With notes.io;

  • * You can take a note from anywhere and any device with internet connection.
  • * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
  • * You can quickly share your contents without website, blog and e-mail.
  • * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
  • * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.

Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.

Easy: Notes.io doesn’t require installation. Just write and share note!

Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )

Free: Notes.io works for 12 years and has been free since the day it was started.


You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;


Email: [email protected]

Twitter: http://twitter.com/notesio

Instagram: http://instagram.com/notes.io

Facebook: http://facebook.com/notesio



Regards;
Notes.io Team

     
 
Shortened Note Link
 
 
Looding Image
 
     
 
Long File
 
 

For written notes was greater than 18KB Unable to shorten.

To be smaller than 18KB, please organize your notes, or sign in.