Recent Activity
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
2
Hi,
DISCLAIMER: This might be a very niche problem peculiar to trying to mapping New Zealand territory with the GeoRegion object in SAS Viya 3.5 and Visual Analytics 8.5.2. The Map Service in use is OpenStreetMap. All data shown in screenshots are dummy data created just for illustration.
Quick Summary We are trying to create a VA report with the GeoRegion object to map our business data to each of the regions defined by the shape files supplied by Statistics New Zealand (Stats NZ Geographic Data Service).
What We Need We are looking for a way to instruct the VA GeoRegion map object to centre itself on the 180-degree line of longitude, and not the zero-degrees line of longitude, so that all of the territory of New Zealand appears together when the report opens. We would need to do this for all of our reports, not just as a one-off.
More Detailed Bits
New Zealand consists of four main islands, North Island, South Island, Stewart Island and The Chatham Islands.
The problem that we have seems to be due to The Chatham Islands being located on the other side of the 180-degree line of longitude, separate from the remainder of New Zealand, as shown in the screenshot below where the red vertical line is an approximation of the 180-degree line of longitude.
The result of this positioning is that, when we need to represent business data across all of New Zealand territory (including the Chatham Islands), the GeoRegion map opens to show the entire world map, with The Chatham Islands completely separated from the rest of the mapped instance New Zealand, as shown in the screenshot below.
We know that by simply filtering out the regions that make up The Chatham Islands our report opens nicely zoomed in to just the main body of New Zealand territory. However, our users must include The Chatham Islands in their reports, so filtering their data out is not an option.
We believe that this separation is happening because the GeoRegion map object draws the land masses in a left-to-right pattern from West 180-degrees (on the far left) to East 180-degrees (on the far right) and thus zero-degrees in the middle of the map.
We have tried several different projections offered by Statistics New Zealand to drive our Geographic Data Provider used for this report, but all of them, so far adopt this same layout (the example report above is using EPSG:4326).
I think that New Zealand may be the only country that has close-by territory (800kms in the case of The Chathams), but where territory is separated by the 180-degree line of longitude, but I am optimistic that someone out there has seen this problem and resolved it.
Any bright ideas out there, ironically, in the rest of the world ?😃
Many thanks,
Downunder Dave Wellington
... View more

0
0
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
22
Dear All I wanted to run Monte Carlo Simulation - Run 10 Iterations but dont know that why its giving me the same out for all 10 itertaions (output attached). I have used chatgpt & deepseek but its of no support. I have attached dataset as well as sas coding script. Would appreciate support by pasting code completely or answering me after checking 1st that its working in sas on demand. Thank you /* Step 4: Monte Carlo Simulation - Run 10 Iterations for Random Loss Outcomes */ data montecarlo; set portfolio_sim; do sim_id = 1 to 10; /* Introduce random variation to PD and LGD */ random_PD = rand("NORMAL", Sim_PD, 0.01); random_LGD = rand("NORMAL", Sim_LGD, 0.05); random_PD = max(0, min(random_PD, 1)); random_LGD = max(0, min(random_LGD, 1)); sim_loss = random_PD * random_LGD * EAD * Current_Balance; output; end; run; OR data montecarlo; set portfolio_sim; /* Convert alphanumeric Borrower_ID to numeric seed */ numeric_id = input(compress(Borrower_ID, , 'kd'), 8.); do sim_id = 1 to 10; /* Create unique seed for each borrower-simulation combination */ seed = numeric_id * 100 + sim_id; call streaminit(seed); /* Generate random values */ random_PD = rand("NORMAL", Sim_PD, 0.01); random_LGD = rand("NORMAL", Sim_LGD, 0.05); /* Constrain to valid ranges */ random_PD = max(0, min(random_PD, 1)); random_LGD = max(0, min(random_LGD, 1)); /* Calculate loss */ sim_loss = random_PD * random_LGD * EAD * Current_Balance; output; end; drop numeric_id seed; /* Clean up temporary variables */ run;
... View more

0
12
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
0
Unanswered topics
These topics from the past 30 days have no replies. Can you help?
Subject | Likes | Author | Latest Post |
---|---|---|---|
0 | |||
0 | |||
0 | |||
0 | |||
0 | |||
0 | |||
1 | |||
1 | |||
0 | |||
0 |