Missing data in SAS data step - sas

This is the first time I've asked a question here so bear with me :)
I am working in SAS Enterprise Guide.
I have two data sets that contain data from several years, including 2020 (ASH_Kit1 and ASH_Kit 2 referenced in the code below). However, after I run the following data step, the resulting data set does not contain any data from 2020 even though those two sources of data for this code contain plenty of data for 2020. Anybody have any ideas as to why the 2020 data is disappearing? Please let me know if I can clarify my question at all. Thanks!
Data ash.home_master_appended_onekit;
Set
tmp7day.ASH_Kit1
tmp7day.ASH_Kit2
;
Run;
Quit;

Your code seems to be completely fine. As you can see in the next example, when you are concatenating/appending 2 datasets, all the data is retrieved:
Code:
data ash_kit1;
input id year;
datalines;
1 2019
2 2019
3 2020
;
run;
data ash_kit2;
input id year;
datalines;
4 2019
5 2019
6 2020
;
run;
Data home_master_appended_onekit;
Set
ash_kit1
ash_kit2
;
Run;
Output home_master_appended_onekit:
id
Year
1
2019
2
2019
3
2020
4
2019
5
2019
6
2020
My recommendation would be to check the structure of both datasets. Make sure they have the same columns and the same data types in the same order, so you can concatenate them correctly.
Sources:
Combining datasets in SAS

Related

SAS Proc Freq Not Displaying Values

I am doing some simple cross tabulations using Proc Freq, but I'm noticing that the output SAS gives me doesn't contain any frequency counts; I'm only getting percents.
Here is an example code that I ran in SAS (I am using SAS 9.4):
data test;
input year 1-5 group $6;
cards;
2018 A
2018 A
2018 B
2018 B
2019 A
2019 A
2019 A
2019 B
;
run;
proc freq data = test;
table year * group / norow nopercent;
run;
I'm expecting a table that has the frequency counts with the column percentage below, but instead, this is what SAS is giving me:
Does anyone know how I can get the frequency values to be shown?
I ran your code and got this. I reckon there is something you are not telling us.
Thank you all for your help- I found the issue. It looks like there was an issue with the cross-tab frequency template that came with SAS. I was able to restore it by using the following code:
proc template;
delete base.freq.crosstabfreqs;
run;
Thank you all for your help!
#_null_ your image is NOT the output I get when running the questions code.
The Frequency and Col Pct are NOT in row header cells, and instead are shown in a box offset to the left from the table.

Microsoft Power BI: Line chart last 13 weeks data for 3 years

I need to show line chart visual for last 13 years data for 2017,2018 and 2018. Can anyone tell me how I can achieve this?
I have a table called Profit
columns : Profit, WeekEndingDate, Year
I tried to create last 13 weeks measure but only showed 7 weeks as we are only 7 weeks in 2019 and also only showed data for 2018 and 2019.
I need to display each year individually with 13 weeks data.
Assuming these are linked to dates.
You can use the visual filters to show a date range from today and step back 3 months
Edit:
could you post the measure you created to get the last 13 weeks, it needs to be edited to ignore year. that should do the trick

Plotting seasonal data, with years on top of each other in SAS?

Hi I have a time series data table from October 2013 to October 2016. I would like to plot the time series from October 2013 to November 2014, October 2014 to November 2015, and October 2015 to November 2016 on top of each other on the same graph to analyze any seasonal trends.
My idea is to create separate data tables with each subsegment, but is there an easier way to do this in SAS?
This is an example of the data table I want to plot the seasonality of.
The workflow I think here is to add a group variable that indicates, say, year, which has the same value for all rows you want plotted in one plot-grouping.
Then you use the group statement in whatever plot type you want. Something like:
data stocks_years;
set sashelp.stocks;
date_year = intck('YEAR','01AUG1986'd,date,'c')+1986;
date_month= month(date);
run;
proc sgplot data=stocks_years;
vline date_month/response=close group=date_year stat=mean;
run;
This is an example of doing that to see the average close per month of the three stocks in the SASHELP.STOCKS dataset. It is a terrible plot of course but it should give you some idea of what it would look like. Each of those differently colored lines is from a different year (aug->jul being defined as a year, with the number being the year number of aug).
The lead off provided by Joe gave me everything I needed. Here is the completed code for anyone else's reference.
%macro Plot_Seasonal_Worse_TP(tbl_name, tp, cutoff_date);
/*tp = transition probability */
proc sql;
create table &tbl_name._trim as
SELECT *
FROM &tbl_name
WHERE asofdt > &cutoff_date;
run;
data &tbl_name._trim;
set &tbl_name._trim;
date_year = intck('YEAR','01NOV2013'd,asofdt,'c')+2014;
date_month= MOD(month(asofdt)+2, 12); /* move november and december of previous year to front of time series */
run;
proc sgplot data=&tbl_name._trim;
vline date_month/response=&tp group=date_year;
title &tbl_name (&tp);
run;
%mend Plot_Seasonal_Worse_TP;
Output looks like this as well.

Stacked bar chart by group and subgroup in SAS

I am unable to create stacked charts by group and subgroup in sas9.4, I want charts which are similar to excel graphs. Please find the sample data and excel graph below (first image) and also the SAS graph (second image).
I am unable to set the common year for the SEGMENT 'ACTUAL' AND 'FORECAST' on the same axis (year). The actual means the data has up to 2014 and forecast means after 2014, Both should fall in the same axis.
goptions reset=all ;
goptions colors=(red blue green);
legend1 label=none ;
proc gchart data=NEW;
vbar year/ discrete type=sum sumvar=VALUE
group= segment subgroup=WKSCOPE ;
where year le 2020 AND YEAR ge 2012;
run;
I would solve this with annotation. I know SGPLOT better than GCHART so I'll answer it this way.
data have;
input segment $ year wkscope $ value;
datalines;
ACTUAL 2012 PH 5
ACTUAL 2012 PH 1
ACTUAL 2012 BHS 1
ACTUAL 2012 RES 2
ACTUAL 2013 PH 2
ACTUAL 2013 PH 5
ACTUAL 2013 BHS 1
ACTUAL 2014 RES 2
FORECAST 2015 PH 3
FORECAST 2015 BHS 0
FORECAST 2016 PH 4
FORECAST 2016 RES 1
FORECAST 2017 PH 5
FORECAST 2017 BHS 1
FORECAST 2017 RES 2
;;;;
run;
data sgannods;
x1space='wallpercent';
y1space='wallpercent';
x1=75;
y1=-10;
label="Forecast";
function='text';
output;
x1=25;
label="Actual";
output;
run;
proc sgplot data=have sganno=sgannods;
vbar year/response=value group=wkscope groupdisplay=stack;
run;
Basically, do everything except segment, then annotate using that value. You can generate it by hand like I do, or (preferably) generate it from the original data if it could change. I use WALLPERCENT since it's going to be first half is actual last half is forecast, but if it could change (2 actual 4 forecast) then you shouldn't do that; you should either use WALLPERCENT and work out the proper position from the data (with a proc freq, probably) or use DATAVALUE and put it under the middle value.
If this isn't close enough, I would go to robslink.com, which has a nice set of examples (and is written by one of the developers of the GCHART set of procs). Sanjay also has a blog, Graphically Speaking which has some great examples, and both post on SAS Communities.
The image I produce follows here. It's not particularly close in other manners but all of those are easy to fix (color scheme, sizes, location of legends).
Data labels are the one thing you can't really have this way; they're addable if you use VBARPARM, but that requires summarizing the data ahead of time. Sanjay covers this in one of his blog posts about 9.4M2 (if you have the M2 maintenance release); I also cover this in my MWSUG Paper, Labelling without the Hassle: How to Produce Labeled Stacked Bar Charts Using
SGPLOT and GTL Without Annotate if you have an older version.

insert columns that are missing in a range

I've created panel data by transposing columns, based on weeks, and some of the weeks never had observations, so those weeks never showed up as columns. Is there a reasonable way to insert the weeks that had no observations.
I need week0-week61, but currently I am missing week0, week4, week8... It seems silly to do this by hand in excel.
The simplest way is like this:
data ttt;
input id week0 week4;
datalines;
1 10 20
2 11 21
;
data ttt1;
set ttt;
array a{*} week0-week61;
run;