I currently have two tables. The first one has a bunch of information. The relevant information is the maj_cvg_code which has a value of 'opv', 'pro', 'ipa' and a maj_diag_code which is some number. When you combine both of these pieces of information you will get an actual name for each row.
The second table has the maj_cvg_code and maj_diag_code and the name. How do I get SAS/SQL to print the name of the category on each row?
Related
I have a table of data in Excel. Column A contains Names, Column B contains their interest. Each interest has a separate row. I want to take the data from this table and have a single row with the name of the customer and a column for each of their interests. IE RAW Data:
I am looking to take the 4000 row table and grouping by the name. I am unsure how many times each name appears in the list (Once or Fifty times) but I want the interests placed on a single row with each interest in a separate column EG Desired Data:
I have tried the standard transpose....html table....and pivot tables but it will put the interests all in a row along the top regardless if the customer is interested or not and using a record count T/F that means the data sheet in harder to understand then if I leave it as one block and sort by name
Sure I am not alone with this but all searches for the past 2 hrs keep returning pivot/transpose or duplicate items. Any is appreciated
If you don't want to use VBA, you could first add a column, for instance in column C, with the title "InterestNum."
In C2, just put 1.
In C3, put =COUNTIF($A$2:$A2, $A3) + 1. This will find the number interest it is for the person.
Make a lookup column, for instance in column D. In D2, put =A2&C2
Then, make a list of all the people. I assume that you put this list starting in cell A2 of a new sheet. Then put headers starting in B1 so that B1 contains the title "1" and C1 contains the title "2" standing for the interest number and as many columns as you wish.
Then in Cell B2, put the formula =IF(ISNA(MATCH($A2&B$1,data!$D$2:$D$5,0)),"",INDEX(data!$B$2:$B$5,MATCH($A2&B$1,data!$D$2:$D$5,0)))
This assumes that your original data is in the data tab. I only tested with 4 rows, so you would need to change $D$2:$D$5 to have as many rows as you do. This works by looking up a combination of the name and interest number. It first checks to see if that combination exists in the data. If not, it leaves that interest blank. If so, it finds the actual interest by going to the same row of the lookup.
First remove duplicates using standard excel functionality to prevent having the same interest twice for a person.
Now, you could of course use VBA and perform exactly what you need.
However, I suggest that you use the pivot table.
If your data looks something like this...
... just use "Insert | Pivot table" and insert a pivot table to a new worksheet.
Then, configure the columns as follows:
Et voilĂ , there you have all your interests listed only once and if a person shares an interest, there is a "1".
If you would rather use VBA, just comment and I will edit my answer.
I am trying to add a column to tablix that uses different dataset. Now the dataset1 holds new data and dataset2 holds old comparison data.
The tablix is using dataset1 and the row in question is grouped by D_ID now I added a column that needs to binded with D_ID(dataset1) to D_ID(dataset2)
=-1*sum(Lookup(Fields!D_ID.Value, Fields!D_ID.Value, Fields!BUD_OLD.Value, "OLD")+Lookup(Fields!D_ID.Value, Fields!D_ID.Value, Fields!ACK_BUD_OLD.Value, "OLD"))
However this does take into account that what I need is all the rows from BUD_OLD with D_ID = smth to be summed together. The lookup only returns one value not a sum of all values with D_ID.
Example
D_ID SUM(BUD_NEW+ACK_BUD_NEW) SUM(BUD_OLD+ACK_BUD_OLD)
**100** **75** (40+35) **15**(SHOULD BE 15+20=35)
How can I get the sum?
LOOKUP only gets a single value.
You would need to use LOOKUPSET and a special function to SUM the results.
Luckily, this has been done before.
SSRS Groups, Aggregated Group after detailed ones
From BIDS:
LOOKUP: Use Lookup to retrieve the value from the specified dataset for a name-value pair where there is a 1-to-1 relationship.
For example, for an ID field in a table, you can use Lookup to
retrieve the corresponding Name field from a dataset that is not bound
to the data region.
LOOKUPSET: Use LookupSet to retrieve a set of values from the specified dataset for a name-value pair where there is a 1-to-many
relationship. For example, for a customer identifier in a table, you
can use LookupSet to retrieve all the associated phone numbers for
that customer from a dataset that is not bound to the data region.
Your expression requires a second "sum"
Try the following:
-1*sum(Lookup(Fields!D_ID.Value, Fields!D_ID.Value, Fields!BUD_OLD.Value, "OLD")+SUM(Lookup(Fields!D_ID.Value, Fields!D_ID.Value, Fields!ACK_BUD_OLD.Value, "OLD")
I know the title might seem confusing but the real situation is as follow: I have two tables with existing data and both of them have n rows but different columns. The order of the rows in two tables do match. So the goal is such that after appending, the first row of the second table is appended to the first row of the first table, etc. and all the columns from the second table are added to the first table - basically just like paste two tables together.
I have multiple databases that contain pieces of data that I need to collect on my clients. Without giving any specific examples, due to confidentiality of the actual data, I will simply refer to what the field names are.
My Master table and three other tables contain the following columns -
Social Security Number,
Medicare Number,
Medicaid Number,
Phone Number,
Date of Birth,
Last Name,
First Name
The goal is to read a master record and, if all of the specified fields do not contain data, go and look at the other data sources to see if one of them DO contain the missing data.
Let me tell you an example of what the problem might be and see what suggestions you can give me to help me achieve my goal. In my example I will call the master table Table 1.
Table 1 - Is missing the DOB, SSN & Medicaid# for this record.
Table 2 - Contains the DOB, Medicare# and Last & First Name.
Table 3 - Has DOB, Medicaid#, Phone Number and Last & First Name.
Table 4 - DOB, SSN, Medicare#, and Phone Number, and Last & First Name.
Currently, I am doing the following:
I created a view called View 1 to combine all of the tables together. The uncommon fields are simply NULL for the tables no containing the field.
I have nested case statements for each of the desired fields. I look to see if the field in Table 1 is NULL, I begin doing a SubSelect statement to look for a matching record in the View 1 for each of the possible matching fields along with any secondary field to double check when needed - like if I do just DOB and Last & First Name matches.
I have a temporary table that gets updated with the findings prior to me running through the checks again. I run through it multiple times since the first time through it might not have had a hit with one field, but the second time through it would find a match.
Does anyone see a better way of doing it thn what I have described?
This is the part that loses me:
I have a temporary table that gets updated with the findings prior to
me running through the checks again. I run through it multiple times
since the first time through it might not have had a hit with one
field, but the second time through it would find a match.
Without that I would suggest left joining the tables to the master then using COALESCE() to find your best NOT NULL value.
COALESCE(Table_1.DOB,Table_2.DOB,Table_3.DOB,Table_4.DOB)
I have these tables below in access
tblBaseResults is where the base info is.
I use this query to get count of the Activity names in tblBaseResults
SELECT tblBaseResults.Activity, Count(tblBaseResults.Activity) AS CountOfActivity INTO tblCountResults
FROM tblBaseResults
GROUP BY tblBaseResults.Activity;
This produces my table tblCountResults.
What i need it to bring then Name from tblBaseResults over to a new column on tblCountResults where the Activity matches. Also i would only like to bring over fields that DO NOT contain ?. Some will contain question marks and if thats all there is thats fine. but i would prefer to bring over fields without question marks first.