Recent Activity
sas code which fetch all the dataset that are modified and created in may’25 and their count from grp/credit lib. Actually i want exact count of dataset that are created or modified in may month from grp/credit lib.
... View more

0
2
I am Learning the proc template. I tried to create a box plot with sashelp.cars. I've got to make it 80% of what I am thinking , I am stuck at the last 20 % to finish. Looking for help. My code creates graph correctly but stuck at creating the legend. Present graph only show the group legends text in legends, but 1. I want to add the number of to the legends text to display the counts. like (SUV-Asia (N= 25)). I tried creating the macro variable for counts and attach to the group., but it messing up my graph. 2. Is it possible to to diplay all the Asia related in one column, USA in another column, and Europe in another columns in Legends Here is my cars code *create data;
proc sql;
create table car_subjects as
select distinct
cats(Make, "-", Model) as USUBJID length=50,
Type as CarType length=15,
Origin as Region length=15,
Horsepower,
Weight,
MPG_City,
MPG_Highway,
MSRP
from sashelp.cars
where Make is not null and Model is not null;
quit;
*get Count to display in legend;
proc sql;
create table car_counts as
select CarType, Region, count(*) as N
from car_subjects
group by CarType, Region;
quit;
* Add count to dataset;
proc sort data=car_subjects;
by CarType Region;
run;
proc sort data=car_counts;
by CarType Region;
run;
/* Step 4: Merge and build final dummy dataset */
*try with few groups first;
data dummy_cars_final ( where = (region in ('USA' 'Asia' 'Europe') and cartype in ('SUV' 'Sedan' 'Truck')));
merge car_subjects(in=a) car_counts;
by CarType Region;
if a;
/* Derived variables */
region_type = catx("-", CarType, Region);
Score = round(40 + ranuni(0)*60, 0.1);
PowerIndex = round((Horsepower * 0.6 + Weight * 0.0005), 0.1);
EcoScore = round((MPG_City * 0.4 + MPG_Highway * 0.6), 0.1);
length LuxuryLevel $10;
if MSRP > 50000 then LuxuryLevel = "High";
else if MSRP > 30000 then LuxuryLevel = "Medium";
else LuxuryLevel = "Low";
drop Horsepower Weight MPG_City MPG_Highway MSRP;
run;
proc template;
define statgraph boxplot_template;
begingraph;
discreteattrmap name="comboMap" / ignorecase=true;
value "SUV-Asia" / fillattrs=(color=orange);
value "SUV-Europe" / fillattrs=(color=orange) ;
value "SUV-USA" / fillattrs=(color=orange) ;
value "Sedan-Asia" / fillattrs=(color=magenta) ;
value "Sedan-Europe" / fillattrs=(color=orange);
value "Sedan-USA" / fillattrs=(color=magenta);
value "Truck-Asia" / fillattrs=(color=grey) ;
value "Truck-USA" / fillattrs=(color=grey);
enddiscreteattrmap;
discreteattrvar attrvar=patgroup var=region_type attrmap='comboMap';
layout lattice / rows=2 columns=1 columndatarange=union ROWWEIGHTS=(.75 .25) ;
layout overlay /
xaxisopts=(label="Region" labelattrs=(size=12pt weight=bold)
tickvalueattrs=(size=12pt weight=bold))
yaxisopts=(offsetmin=0.05 offsetmax=0.05 label="Rating Score"
linearopts=(tickvaluesequence=(start=0 end=100 increment=10)));
boxplot x=region y=score /
name='BoxLegend'
group=patgroup
groupdisplay=cluster
boxwidth=0.6 clusterwidth=0.5
display=( median mean caps fillpattern )
medianattrs=(pattern=1);
endlayout;
discretelegend 'BoxLegend' /
border=false
valueattrs=(size=8pt weight = bold)
across=3 location=inside valign=top ;
endlayout;
endgraph;
end;
run;
proc template;
define style styles.mypatterns;
parent=styles.listing;
style GraphData1 from GraphData1 / fillpattern="R1" ;
style GraphData2 from GraphData2 / fillpattern="X1" ;
style GraphData3 from GraphData3 / fillpattern="E" ;
style GraphData4 from GraphData4 / fillpattern="R1" ;
style GraphData5 from GraphData5 / fillpattern="X1" ;
style GraphData6 from GraphData6 / fillpattern="E" ;
style GraphData7 from GraphData7 / fillpattern="R1" ;
style GraphData8 from GraphData8 / fillpattern="X1" ;
style GraphData9 from GraphData9/ fillpattern="E" ;
end;
run;
options orientation=landscape;
ods rtf file="boxplot_grouped.rtf" style=mypatterns;
ods graphics / reset width=8.5in height=5.5in border=off;
proc sgrender data=Dummy_cars_final template=boxplot_template;
run;
ods rtf close; Thank you.
... View more

0
26
I would like the lines below for c1= to c4= to go on for 14 columns. That means col5 is col14 and I should have c1= to c14=.
Could someone please share a macro to do this loop?:
data a; set tran; const=0; c1=log((sum(of col1-col1)+const)/(sum(of col2-col5)+const)); c2=log((sum(of col1-col2)+const)/(sum(of col3-col5)+const)); c3=log((sum(of col1-col3)+const)/(sum(of col4-col5)+const)); c4=log((sum(of col1-col4)+const)/(sum(of col5-col5)+const)); run;
... View more

0
5
If my table has 1Million records, I want to:
1) sort by largest to smallest by price
2) take the first 100K and call it 'group 1'.....then the next 100K and call it 'group 2' and so on
How can I do it?
proc sort would sort the data
but I am not sure how can I label the records based on the a group of x records.
As an example, I have attached a list of 30 records, and grouped them in 3 creating 10 groups(attached excel)
... View more

0
4
Hi everyone, I’m connecting an Oracle database (Latin-1 character set) to a SAS Viya 4 (2024.03 LTS) session configured with UTF-8 encoding using the Oracle LIBNAME engine. When displaying data from tables containing accented characters, every non-ASCII byte appears corrupted as “?”. For example: Original: "Não informado" Displayed: "N?o informado" I've found the following encoding-related options for the LIBNAME statement: DBCLIENT_ENCODING_FIXED= (YES|NO, based on SAS encoding) DBCLIENT_MAX_BYTES= (Maximum number of bytes per character of the SAS session encoding) DBSERVER_ENCODING_FIXED= (YES|NO, based on Oracle server encoding) DBSERVER_MAX_BYTES= (usually 1) What would be the recommended combination of these encoding options to correctly handle transcoding from Latin-1 to UTF-8? Are these options the correct or the only way to force proper transcoding from Latin-1 (Oracle) to UTF-8 (Viya 4) without data corruption? If not, could you recommend the best practice settings or any additional parameters required? Any examples or guidance would be greatly appreciated! Thanks in advance!
... View more

0
2
Unanswered topics
These topics from the past 30 days have no replies. Can you help?