- Get link
- X
- Other Apps
%MACRO | %IF |% SYSFUNC | %IF %THEN % DO | % PROC PRINT | %MEND
%macro print_first10(dsname);
%if %sysfunc(exist(&dsname.)) %then %do;
proc print data=&dsname. (obs=10);
title "First 10 Observations of &dsname.";
run;
%end;
%else %do;
%put ERROR: Dataset &dsname. does not exist!;
%end;
%mend print_first10;
/* Example Usage */
%print_first10(sashelp.class);
output:
First 10 Observations of sashelp.class |
Obs | Name | Sex | Age | Height | Weight |
---|---|---|---|---|---|
1 | M | 12 | 57.3 | 83.0 | |
2 | M | 12 | 59.0 | 99.5 | |
3 | F | 13 | 56.5 | 84.0 | |
4 | F | 15 | 66.5 | 112.0 | |
5 | Alfred | M | 14 | 69.0 | 112.5 |
6 | Alice | F | 13 | 56.5 | 84.0 |
7 | Barbara | F | 13 | 65.3 | 98.0 |
8 | Carol | 14 | 62.8 | 102.5 | |
9 | Carol | F | 14 | 62.8 | 102.5 |
10 | Henry | M | 14 | 63.5 | 102.5 |
%print_first10(sashelp.cars);
output:
First 10 Observations of sashelp.cars |
Obs | Make | Model | Type | Origin | DriveTrain | MSRP | Invoice | EngineSize | Cylinders | Horsepower | MPG_City | MPG_Highway | Weight | Wheelbase | Length |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
1 | Acura | MDX | SUV | Asia | All | $36,945 | $33,337 | 3.5 | 6 | 265 | 17 | 23 | 4451 | 106 | 189 |
2 | Acura | RSX Type S 2dr | Sedan | Asia | Front | $23,820 | $21,761 | 2.0 | 4 | 200 | 24 | 31 | 2778 | 101 | 172 |
3 | Acura | TSX 4dr | Sedan | Asia | Front | $26,990 | $24,647 | 2.4 | 4 | 200 | 22 | 29 | 3230 | 105 | 183 |
4 | Acura | TL 4dr | Sedan | Asia | Front | $33,195 | $30,299 | 3.2 | 6 | 270 | 20 | 28 | 3575 | 108 | 186 |
5 | Acura | 3.5 RL 4dr | Sedan | Asia | Front | $43,755 | $39,014 | 3.5 | 6 | 225 | 18 | 24 | 3880 | 115 | 197 |
6 | Acura | 3.5 RL w/Navigation 4dr | Sedan | Asia | Front | $46,100 | $41,100 | 3.5 | 6 | 225 | 18 | 24 | 3893 | 115 | 197 |
7 | Acura | NSX coupe 2dr manual S | Sports | Asia | Rear | $89,765 | $79,978 | 3.2 | 6 | 290 | 17 | 24 | 3153 | 100 | 174 |
8 | Audi | A4 1.8T 4dr | Sedan | Europe | Front | $25,940 | $23,508 | 1.8 | 4 | 170 | 22 | 31 | 3252 | 104 | 179 |
9 | Audi | A41.8T convertible 2dr | Sedan | Europe | Front | $35,940 | $32,506 | 1.8 | 4 | 170 | 23 | 30 | 3638 | 105 | 180 |
10 | Audi | A4 3.0 4dr | Sedan | Europe | Front | $31,840 | $28,846 | 3.0 | 6 | 220 | 20 | 28 | 3462 | 104 | 179 |
%print_first10(sashelp.clas);
log:
/* Example Usage */
39 %print_first10(sashelp.clas);
ERROR: Dataset sashelp.clas does not exist!
PRACTICE AND COMMENT YOUR CODE:
-->PLEASE READ AND COMMENT THE BLOG...
--PLEASE FOLLOW THE BLOG FOR MORE UPDATES...
--FOLLOW US IN FACEBOOK SASALL4YOU AND JOIN ...
--JOIN US IN FACEBOOK AND TELEGRAM CHANNEL FOR MORE UPDATES
CLICK HERE : https://t.me/SasAll4You
- Get link
- X
- Other Apps
Comments
Post a Comment