I've got a dataset where I've been working a while to clean it up from wide to long format.
We're following about 1.000 patients with 1-5 aneurysms (can have more than 1 aneurysm) and some or all are treated with different available treatments. The patient can have two aneurysms where one is treated with treatment A and the other is treated with treatment B.
Here's an example of the data:
* Example generated by -dataex-. To install: ssc install dataex
clear
input str32 record_id float treatmentChoice_ byte(treatment_1 treatment_3) float aneurysm_id
"007128de18ce5cb1635b8f27c5435ff3" . . . 1
"007128de18ce5cb1635b8f27c5435ff3" . . . 2
"00abd7bdb6283dd0ac6b97271608a122" . 2 . 1
"00abd7bdb6283dd0ac6b97271608a122" . . . 2
"0142103f84693c6eda416dfc55f65de1" . 1 . 1
"0142103f84693c6eda416dfc55f65de1" . . . 2
"0153826d93a58d7e1837bb98a3c21ba8" . . . 1
"0153826d93a58d7e1837bb98a3c21ba8" . . . 2
"01c729ac4601e36f245fd817d8977917" . 1 . 1
"01c729ac4601e36f245fd817d8977917" . . . 2
"01dd90093fbf201a1f357e22eaff6b6a" . . . 1
"01dd90093fbf201a1f357e22eaff6b6a" . 1 . 2
"0208e14dcabc43dd2b57e2e8b117de4d" . . . 1
"0208e14dcabc43dd2b57e2e8b117de4d" . 1 . 2
"0210f575075e5def7ffa77530ce17ef0" . . . 1
"0210f575075e5def7ffa77530ce17ef0" . . . 2
"022cc7a9397e81cf58cd9111f9d1db0d" . . . 1
"022cc7a9397e81cf58cd9111f9d1db0d" . . . 2
"02afd543116a22fc7430620727b20bb5" . 2 . 1
"02afd543116a22fc7430620727b20bb5" . . . 2
"0303ef0bd5d256cca1c836e2b70415ac" . . . 1
"0303ef0bd5d256cca1c836e2b70415ac" . 1 . 2
"041b2b0cac589d6e3b65bb924803cf1a" . . . 1
"041b2b0cac589d6e3b65bb924803cf1a" . . . 2
"0536317a2bbb936e85c3eb8294b076da" . . . 1
"0536317a2bbb936e85c3eb8294b076da" . 1 . 2
"06161d4668f217937cac0ac033d8d199" . . . 1
"06161d4668f217937cac0ac033d8d199" . . . 2
"065e151f8bcebb27fabf8b052fd70566" . . 1 1
"065e151f8bcebb27fabf8b052fd70566" . . . 2
"065e151f8bcebb27fabf8b052fd70566" . . . 3
"065e151f8bcebb27fabf8b052fd70566" . . . 4
"07196414cd6bf89d94a33e149983d102" . . . 1
"07196414cd6bf89d94a33e149983d102" . . . 2
"0721c38f8275dab504fc53aebcc005ce" . . . 1
"0721c38f8275dab504fc53aebcc005ce" . . . 2
"0721c38f8275dab504fc53aebcc005ce" . . . 3
"0721c38f8275dab504fc53aebcc005ce" 1 . . 4
"07bef516d53279a3f5e477d56d552a2b" . . . 1
"07bef516d53279a3f5e477d56d552a2b" . 2 . 2
"08678829b7e0ee6a01b17974b4d19cfa" . . . 1
"08678829b7e0ee6a01b17974b4d19cfa" . . . 2
"08bb6c65e63c499ea19ac24d5113dd94" . . . 1
"08bb6c65e63c499ea19ac24d5113dd94" . . . 2
"08f036417500c332efd555c76c4654a0" . . . 1
"08f036417500c332efd555c76c4654a0" . . . 2
"090c54d021b4b21c7243cec01efbeb91" . . . 1
"090c54d021b4b21c7243cec01efbeb91" . . . 2
"09166bb44e4c5cdb8f40d402f706816e" . . . 1
"09166bb44e4c5cdb8f40d402f706816e" . 1 . 2
"0930159addcdc35e7dc18812522d4377" . . . 1
"0930159addcdc35e7dc18812522d4377" . . . 2
"096844af91d2e266767775b0bee9105e" . . . 1
"096844af91d2e266767775b0bee9105e" . 2 . 2
"09884af1bb9d59803de0c74d6df57c23" . . . 1
"09884af1bb9d59803de0c74d6df57c23" . 2 . 2
"09e03748da35e9d799dc5d8ddf1909b5" . . . 1
"09e03748da35e9d799dc5d8ddf1909b5" . . . 2
"0a4ce4a7941ff6d1f5c217bf5a9a3bf9" . . . 1
"0a4ce4a7941ff6d1f5c217bf5a9a3bf9" . . . 2
"0a5db40dc58e97927b407c9210aab7ba" 4 . . 1
"0a5db40dc58e97927b407c9210aab7ba" . . . 2
"0a73c992955231650965ed87e3bd52f6" . . . 1
"0a73c992955231650965ed87e3bd52f6" . 2 . 2
"0a84ab77fff74c247a525dfde8ce988c" 1 . 2 1
"0a84ab77fff74c247a525dfde8ce988c" . . . 2
"0a84ab77fff74c247a525dfde8ce988c" . . . 3
"0af333ae400f75930125bb0585f0dcf5" . . . 1
"0af333ae400f75930125bb0585f0dcf5" . . . 2
"0af73334d9d2166191f3385de48f15d2" . 1 . 1
"0af73334d9d2166191f3385de48f15d2" . . . 2
"0b341ac8f396a8cdb88b7c658f66f653" . . . 1
"0b341ac8f396a8cdb88b7c658f66f653" . . . 2
"0b35cf4beb830b361d7c164371f25149" . 1 . 1
"0b35cf4beb830b361d7c164371f25149" . . . 2
"0b3e110c9765e14a5c41fadcc3cfc300" . . . 1
"0b6681f0f441e69c26106ab344ac0733" . . . 1
"0b6681f0f441e69c26106ab344ac0733" . . . 2
"0b8d8253a8415275dbc2619e039985bb" 4 . . 1
"0b8d8253a8415275dbc2619e039985bb" . . . 2
"0b8d8253a8415275dbc2619e039985bb" . . . 3
"0b92c26375117bf42945c04d8d6573d4" . 2 . 1
"0b92c26375117bf42945c04d8d6573d4" . . . 2
"0ba961f437f43105c357403c920bdef1" . . . 1
"0ba961f437f43105c357403c920bdef1" . . . 2
"0bb601fabe1fdfa794a5272408997a2f" . . . 1
"0bb601fabe1fdfa794a5272408997a2f" . . . 2
"0c75b36e91363d596dc46bd563c3f5ef" . 1 . 1
"0c75b36e91363d596dc46bd563c3f5ef" . . . 2
"0d461328a3bae7164ce7d3a10f366812" . . . 1
"0d461328a3bae7164ce7d3a10f366812" . 2 . 2
"0d4cc4eb459301a804cbef22914f44a3" . 1 . 1
"0d4cc4eb459301a804cbef22914f44a3" . . . 2
"0d4e29e11bb94e922112089f3fec61ef" . . . 1
"0d4e29e11bb94e922112089f3fec61ef" . 1 . 2
"0d513c74d667f55c8f4a9836c304149c" . 1 . 1
"0d513c74d667f55c8f4a9836c304149c" . . . 2
"0da25de126bb3b3ee565eff8888004c2" . . . 1
"0da25de126bb3b3ee565eff8888004c2" . 1 . 2
"0db9ae1f2201577f431b7603d0819fa6" . . . 1
end
label values treatment_1 treatment_1_
label def treatment_1_ 1 "Observation", modify
label def treatment_1_ 2 "Afsluttet", modify
label values treatment_3 treatment_3_
label def treatment_3_ 1 "Observation", modify
label def treatment_3_ 2 "Afsluttet", modify
As you can see, in this example there are three different treatments and I have sorted the observations by the record_ID (patients). Notice that each patient (record_ID) can appear more than once. In fact I have expanded the dataset so if a patient has 4 aneurysms, there will be 4 observations as the statistics are based on aneurysms, not patients.
My problem is, it's seemingly random which one of these observations will describe which treatment each aneurysm got, and I would like to add a variable treatment that lists treatment for the corresponding aneurysm ID. Also note treatmentChoice_ means "which treatment did aneurysm 1 get?" and treatmentChoice_1 means "which treatment did aneurysm 2 get?"
Is there a way to perhaps say:
"For each record_ID that is identical, look through treatmentChoice_ and set treatment to that value if aneurysm ID is 1. Then do the same for treatmentChoice_1, treatmentChoice_3 and set treatment to their value if aneurysm ID is 2 or 3 respectively.
If I follow this correctly you want to select one non-missing value from some variables in each observation. For that you can use max() or min() or the rowmin() or rowmax() function from egen.
With your example data (thanks), I got this. Note the two unlabelled values of 4.
. generate treatment = max(treatmentChoice_, treatment_1, treatment_3)
(73 missing values generated)
. label val treatment treatment_1_
. tab treatment
treatment | Freq. Percent Cum.
------------+-----------------------------------
Observation | 16 59.26 59.26
Afsluttet | 9 33.33 92.59
4 | 2 7.41 100.00
------------+-----------------------------------
Total | 27 100.00
Related
I am writing a small program that calculates--recursively--all paths to (0,0) on the grid given some walls that need to be avoided. The grid looks something like this:
. . . . . . . . . . .
| . . | . . . . . . .
. . | . . . . . . . .
. . - - - . . - - - -
. | . . . . . | . . .
. . . . . | . | . . .
. . . . . . - - . . .
. - - - . . . | . . .
. | . . . . . | . . .
. | . . . . . . . . .
. . . | . . . . . . O
You must get to the origin without ever increasing distance to the origin in your path.
I have written this code to find all paths:
int recursive_find_path(unsigned int x, unsigned int y, unsigned int distance, std::vector<std::vector<GRID_STATUS> > blocked_grid){
//if(x>blocked_grid.size()-1 or y>blocked_grid[x].size()-1 or x<0 or y<0 or x+y > distance or blocked_grid[y][x] == GRID_BLOCKED or blocked_grid[y][x] == GRID_TRAVELLED)
if(x>blocked_grid.size()-1 or y>blocked_grid[x].size()-1 or x<0 or y<0 or x+y<distance or blocked_grid[y][x] == GRID_BLOCKED){
return 0;
}
if(blocked_grid[y][x] == GRID_TRAVELLED){
return 0;
}
if(x==0 and y==0){
return 1;
}
blocked_grid[y][x] = GRID_TRAVELLED; // set position to 'travelled' on to avoid infinite recursion
return recursive_find_path(x-1,y, distance-1,blocked_grid)+recursive_find_path(x,y-1, distance-1, blocked_grid)+recursive_find_path(x+1,y, distance-1, blocked_grid);
}
NOTE: GRID_TRAVLLED and GRID_BLOCKED are values defined elsewhere in the program but essentially are just tokens to indicate that there is a wall or the point has been travelled on.
However, when running, the program outputs that there are zero paths!
Admittedly, I am not sure how many paths there are but I can at least count a few thus it can't be zero.
Does anyone know what is going wrong here?
Thanks in advance
edit
. . . . . . . . . . . . . . . . . . .
X . . X . . . . . . . . . . . . . . .
. . X . . . . . . . . . . . . . . . .
. . X X X . . X X X X . . . . . . . .
. X . . . . . X . . . . . . . . . . .
. . . . . X . X . . . . . . . . . . .
. . . . . . X X . . . . . . . . . . .
. X X X . . . X . . . . . . . . . . .
. X . . . . . X . . . . . . . . . . .
. X . . . . . . . . . . . . . . . . .
. . . X . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . .
. . . . . . . X . . . . X . . . . . .
. . . . . . . X . . . . . X X X X X X
. . . . . . . X . . . . . . . . . . .
. . . . . . . X . . . . . . . . . . .
. . . . . . . X . . . . . . . . . X S
Using this grid, I get an infinite loop....
updated code:
if(x>blocked_grid.size()-1 or y>blocked_grid[x].size()-1 or x<0 or y<0 or blocked_grid[y][x] == GRID_BLOCKED){
return 0;
}
if(x==0 and y==0){
return 1;
}
return recursive_find_path(x-1,y,blocked_grid)+recursive_find_path(x,y-1, blocked_grid);
}
after letting it sit for a while it did return 540. I am almost certain there can't be 540 paths in this case
I noticed at:
return recursive_find_path(x-1,y, distance-1,blocked_grid)+recursive_find_path(x,y-1, distance-1, blocked_grid)+recursive_find_path(x+1,y, distance-1, blocked_grid);
The two points (x + 1, y) and (x - 1, y) cannot both be closer to the origin, yet you pass (distance - 1) to both of those recursive calls. This will cause distance to eventually equal -1 for many paths, which will then return 0, but until they return 0, those paths will be marked as travelled despite being spurious paths that should have been prevented from being travelled.
You should only check paths that move closer to the origin, those being (x -1, y) and (x, y - 1)
I've taken a project in which the dataset separates the patient information and the disease observation, but the two observations have the same ID. Example:
ID: 12345 Patient age: 23, patient weight: 55, patient height: 180
ID: 12345 Disease progression: A, disease type: abc, Disease risk: 50
This goes on for every patient.
Now I want to run some statistics on this and for that I, as far as I know, have to consolidate this information in ONE observation, so we have patient characteristics and their disease characteristics in one observation. What would be the best way to do this? Bear in mind the two observations have mutually exclusive variables, so they can simply be "grouped" somehow.
* Example generated by -dataex-. To install: ssc install dataex
clear
input str32 record_id byte(treatment gender pcos aneurysmal_finding sz_anu_a_basilaris sz_anu_a_basilaris_2 sz_anu_a_basilaris_4)
"8a36ac06e58a541430cd8b31df3aeef2" . 1 0 2 . . .
"8a36ac06e58a541430cd8b31df3aeef2" . . . . . . .
"2afc1f12901992a1f973cde814615349" . 1 0 2 . . .
"2afc1f12901992a1f973cde814615349" . . . . . . .
"1e00442745c25082a64197b96065f755" . 1 0 2 . . .
"1e00442745c25082a64197b96065f755" . . . . . . .
"c90aef04e29f38fc3e21b919d5106ce8" . 1 0 2 . . .
"c90aef04e29f38fc3e21b919d5106ce8" . . . . . . .
"7cac71f3d31c7e9ec26e6a885ad554ab" . 2 0 2 . . .
"7cac71f3d31c7e9ec26e6a885ad554ab" . . . . . . .
"53c1f08aff25ace9afc46aca3263e7ca" . 1 0 2 . . .
"53c1f08aff25ace9afc46aca3263e7ca" . . . . . . .
"cdbf4328e0724f30950e437bc6bbe262" . 2 0 2 . . .
"cdbf4328e0724f30950e437bc6bbe262" . . . . . . .
"50d722dca92aee72c39c846066850a22" 1 2 0 2 . . .
"50d722dca92aee72c39c846066850a22" . . . . . . .
"ffe78f8927a81a5521f098aa077a755f" . 1 0 1 . . .
"ffe78f8927a81a5521f098aa077a755f" . . . . . . .
"aa2309be5c9b76012462fce3f43a8249" . 1 0 1 . . .
"aa2309be5c9b76012462fce3f43a8249" . . . . . . .
"4917b3d300e195b895e573474be6ccb6" . 1 0 2 . . .
"4917b3d300e195b895e573474be6ccb6" . . . . . . .
"b88557884343831060297ff4b67aeb36" . 1 . 2 . . .
"b88557884343831060297ff4b67aeb36" . . . . . . .
"ebe8ab86719aa71b68d7f0df3e451ce5" . . . 2 . . .
"8dd5267472002c796ce621984f9024ed" . . . . . . 3
"0b3e110c9765e14a5c41fadcc3cfc300" . . . . . . .
"8f58545ef8d37f290d26881743137a72" 1 2 0 2 . . .
"8f58545ef8d37f290d26881743137a72" . . . . . . .
"dcb6a27d1d4f5f1228860a76fa29e5ba" . 1 0 2 . . .
"dcb6a27d1d4f5f1228860a76fa29e5ba" . . . . . . .
"baedce78f2e736fe4d54dbdbe0460694" . 2 0 2 . . .
"baedce78f2e736fe4d54dbdbe0460694" . . . . . . .
"bb1db3b0eca9652cff3c76060b06d60b" 1 2 0 2 . . .
"bb1db3b0eca9652cff3c76060b06d60b" . . . . . . .
"6741bd218feba9de630dfe409a4e50ee" 1 2 0 2 . . .
"6741bd218feba9de630dfe409a4e50ee" . . . . . . .
"1e1425d670466e1a2c6c752d9227df17" . 2 0 2 . . .
"1e1425d670466e1a2c6c752d9227df17" . . . . . . .
"4c6672a06addc8e01842d2741be1857d" . 1 0 2 . . .
"4c6672a06addc8e01842d2741be1857d" . . . . . . .
"f1be80fbb7e4e1f5582780e25bfc8a2c" . 2 0 2 . . .
"f1be80fbb7e4e1f5582780e25bfc8a2c" . . . . . . .
"9991ec586e5f510e161fcad93fb1d79f" . 1 0 2 . . .
"9991ec586e5f510e161fcad93fb1d79f" . . . . . . .
"5c1eb56eccf9cf67ae6065f82b6eb6ce" . 1 0 2 . . .
"5c1eb56eccf9cf67ae6065f82b6eb6ce" . . . . . . .
"f9d10d2eb1951fa2ebc8b0509bb25593" . 1 0 2 . . .
"f9d10d2eb1951fa2ebc8b0509bb25593" . . . . . . .
"fbdf663512805caffe7a99d14fc9561f" . 2 0 2 . . .
"fbdf663512805caffe7a99d14fc9561f" . . . . . . .
"3b55aebe1b4b22e0c77168acc4b775dd" . 1 0 2 . . .
"3b55aebe1b4b22e0c77168acc4b775dd" . . . . . . .
"5f28194ddef4f9d057db2e4fcb7b5cf0" . 1 0 2 . . .
"5f28194ddef4f9d057db2e4fcb7b5cf0" . . . . . . .
"0b8d8253a8415275dbc2619e039985bb" . 1 0 2 5 . .
"0b8d8253a8415275dbc2619e039985bb" . . . . . . .
"4fb152c8524750b65b6717282cceb805" . 1 0 2 . . .
"4fb152c8524750b65b6717282cceb805" . . . . . . .
"ff5136e64c2110c355debca6acb74a13" . 1 0 2 . . .
"ff5136e64c2110c355debca6acb74a13" . . . . . . .
"29534fe6f18b75090b9d18f853ed7ec1" . 1 0 2 5 5 .
"29534fe6f18b75090b9d18f853ed7ec1" . . . . . . .
"8c334d2225db0661b25cf5f2c65fbcb9" . 1 0 2 . . .
"8c334d2225db0661b25cf5f2c65fbcb9" . . . . . . .
"68cf4b9f2db11cb9cf44fd0e03c53f16" . 2 . 2 . . .
"68cf4b9f2db11cb9cf44fd0e03c53f16" . . . . . . .
"6a44e65e7b1f33a3603acf2532bb40f9" . 1 0 2 . . .
"6a44e65e7b1f33a3603acf2532bb40f9" . . . . . . .
"2ed013748bf88df47c39d83bd48d8040" . 1 0 2 . . .
"2ed013748bf88df47c39d83bd48d8040" . . . . . . .
"c2f32f5b61b97d658f7b042b49b8da96" . 1 0 2 . . .
"c2f32f5b61b97d658f7b042b49b8da96" . . . . . . .
"58e1e0b5c29dee7d3739ec582d62b84c" . . . . . . .
"58e1e0b5c29dee7d3739ec582d62b84c" . . . . . . .
"8635b098d70b200fe8eef5dbf7c1c156" . 2 0 2 . . .
"8635b098d70b200fe8eef5dbf7c1c156" . . . . . . .
"266f1f1517fb50bafca92fff39c259d5" . 1 0 2 . . .
"266f1f1517fb50bafca92fff39c259d5" . . . . . . .
"d3df754a7322c02ed89f1208977a19ae" 1 2 0 2 5 . .
"d3df754a7322c02ed89f1208977a19ae" . . . . . . .
"46598c5d2da10731582d6342944e9337" . 1 0 2 . . .
"46598c5d2da10731582d6342944e9337" . . . . . . .
"8c2c5aa9b02eb1092b34cf38c2b1c83d" . 1 0 2 2 . .
"8c2c5aa9b02eb1092b34cf38c2b1c83d" . . . . . . .
"797c9cf7caf53f514f0154f34895fa80" . 1 0 2 . . .
"797c9cf7caf53f514f0154f34895fa80" . . . . . . .
"9b28a68095c520edcb56bee8aa5737b6" . 1 0 2 . . .
"9b28a68095c520edcb56bee8aa5737b6" . . . . . . .
"09e03748da35e9d799dc5d8ddf1909b5" . 1 0 2 . . .
"09e03748da35e9d799dc5d8ddf1909b5" . . . . . . .
"75d5574d8804d24932e3d0d9cbfa4b11" . 1 0 2 . . .
"75d5574d8804d24932e3d0d9cbfa4b11" . . . . . . .
"b5bda504efd4bd3b3be68513ccbf99ef" . 1 0 2 . . .
"b5bda504efd4bd3b3be68513ccbf99ef" . . . . . . .
"dc289c2a5a31355521dde31c4abd4c83" . 1 0 2 . . .
"dc289c2a5a31355521dde31c4abd4c83" . . . . . . .
"76ce83dbd64f05556e903deb54959d22" . 1 0 2 . . .
"76ce83dbd64f05556e903deb54959d22" . . . . . . .
"830ee6dd656938201f4a712607739768" . 1 0 2 . . .
end
label values treatment treatment_
label def treatment_ 1 "I blodfortyndende behandling", modify
label values gender gender_
label def gender_ 1 "Kvinde", modify
label def gender_ 2 "Mand", modify
label values pcos pcos_
label def pcos_ 0 "Nej", modify
label values aneurysmal_finding aneurysmal_finding_
label def aneurysmal_finding_ 1 "Screening", modify
label def aneurysmal_finding_ 2 "Tilfældig fund", modify
label values sz_anu_a_basilaris sz_anu_a_basilaris_
label def sz_anu_a_basilaris_ 2 "7-12 mm", modify
label def sz_anu_a_basilaris_ 5 "Uoplyst", modify
label values sz_anu_a_basilaris_2 sz_anu_a_basilaris_2_
label def sz_anu_a_basilaris_2_ 5 "Uoplyst", modify
label values sz_anu_a_basilaris_4 sz_anu_a_basilaris_4_
label def sz_anu_a_basilaris_4_ 3 "13-25 mm", modify
Essentially my problem could be solved using (assuming this syntax was correct):
gen obs1 = .
replace every variableValue in obs1 == variableValue in 12345
And then just iterating it for 1000s of observations..
On the assumption that each identifier is represented by at most 2 observations, and that each other variable is numeric and represented by a non-missing value in at most 1 observation, you can just collapse. The default collapse by means should work fine.
ds record_id, not
collapse `r(varlist)' , by(record_id)
A more cautious approach would be to check the assumptions first!
Assuming you have loaded both datasets.
First dataset is called dataset1.
Second dataset is called dataset2.
And your ID attribute is called id
Then you can call merge them on id.
use dataset1, clear
merge id using dataset2
I have the following table_1 :
TPMC PWC PWSC Site ET Date Time DIAM PXMC SF
7101 7101 US000521 1 Lathing 08Nov2016 11:58 890.3 1
7102 7102 US000361 1 Lathing 02Nov2016 13:01 878.1 1
7102 7102 UC000348 2 Lathing 07Nov2016 18:22 877.3 1
7106 7106 UC00424 1 Lathing 05Oct2016 9:43 890,4 1
7106 7106 UC00437 3 Lathing 07Nov2016 18:23 877.1 1
7106 7106 UC309 4 Lathing 07Nov2016 18:26 877.8 1
7107 7107 UC05327 1 Lathing 06Oct2016 8:41 837 1
7107 7107 UC200 2 Lathing 13Oct2016 12:53 890.55 1
7108 7108 UC000361 3 Lathing 02Nov2016 13:01 878.1 1
7108 7108 UC00432 1 Lathing 07Nov2016 18:25 877.8 1
7108 7108 UC106 2 Lathing 03Oct2016 9:37 890.3 1
and table_2 :
TPMC PWC PWSC Site ET Date Time DIAM PXMC SF
7101 . . . . 01JAN16 . . . .
7101 . . . . 02JAN16 . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
7101 . . . . 30DEC16 . . . .
7101 . . . . 31DEC16 . . . .
7102 . . . . 01JAN16 . . . .
7102 . . . . 02JAN16 . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
7102 . . . . 30DEC16 . . . .
7102 . . . . 31DEC16 . . . .
I want to merge two tables in a way that the output should look like something:
TPMC PWC PWSC Site ET Date Time DIAM PXMC SF
7101 . . . . 01JAN16 . . . .
7101 . . . . 02JAN16 . . . .
. . . . . . . . . .
7101 7101 US000521 1 Lathing 08Nov2016 11:58 890.3 1
. . . . . . . . . .
. . . . . . . . . .
7101 . . . . 30DEC16 . . . .
7101 . . . . 31DEC16 . . . .
7102 . . . . 01JAN16 . . . .
7102 . . . . 02JAN16 . . . .
. . . . . . . . . .
7102 7102 US000361 1 Lathing 02Nov2016 13:01 878.1 1
7102 7102 UC000348 2 Lathing 07Nov2016 18:22 877.3 1
. . . . . . . . . .
. . . . . . . . . .
7102 . . . . 30DEC16 . . . .
7102 . . . . 31DEC16 . . . .
How can it be done using 'Proc SQL' or 'Data Merge' or 'Combine'?
In the simplest form I used:
data data_set;
set table_1 table_2;
run;
But this produced duplicate values of dates. For example:
TPMC PWC ET PWSC Site Date Time DIAM PXMC SF
7618 . . . 1 29SEP2016 . . .
7618 . . UC00424 2 30SEP2016 . . .
7618 . Lathing UC00437 1 30SEP2016 17:15 890.500000 . .
7618 . Lathing UC309 2 30SEP2016 20:32 890.500000 . .
7618 . . . 3 01OCT2016 . . .
7618 . . . 1 02OCT2016 . . .
I don't know how can I avoid this. I do not want rows where there is no 'ET' (i.e. ET is '.' or empty, I do not want those rows).
Also I want to learn other methods for future use.
One way to append 2 tables is using proc sql.
proc sql;
select t1.* from table1 t1
union all
select t2.* from table2 t2;
quit;
Make sure the 2 tables have exactly the same column names and are structured the same way. If both tables have the same records you'll end up with duplicate rows which you will need to filter.
I will still stick with my answer as in above post...
data table2;
set have001 have002;
run;
Let me see how would I resolve 'duplicate' data issues.
OK, I am using 'ipconfig /displaydns' to display all websites visited (since the last 'ipconfig /flushdns') and I would like to copy just the website's URL to Websites.txt.
A typical layout of the output is:
ocsp.digicert.com
----------------------------------------
Record Name . . . . . : ocsp.digicert.com
Record Type . . . . . : 5
Time To Live . . . . : 17913
Data Length . . . . . : 4
Section . . . . . . . : Answer
CNAME Record . . . . : cs9.wac.edgecastcdn.net
badge.stumbleupon.com
----------------------------------------
Record Name . . . . . : badge.stumbleupon.com
Record Type . . . . . : 1
Time To Live . . . . : 39560
Data Length . . . . . : 4
Section . . . . . . . : Answer
A (Host) Record . . . : 199.30.80.32
0.gravatar.com
----------------------------------------
Record Name . . . . . : 0.gravatar.com
Record Type . . . . . : 5
Time To Live . . . . : 2047
Data Length . . . . . : 4
Section . . . . . . . : Answer
CNAME Record . . . . : cs91.wac.edgecastcdn.net
But, I would wish just to have
ocsp.digicert.com
badge.stumbleupon.com
0.gravatar.com
as the output. Any ideas on how to do that, also I am using a Windows RT device, so external applications are not an option and the output is usually 10 times longer than that, and not all records are the same.
Use PowerShell:
ipconfig /displaydns | Select-String 'Record Name' | ForEach-Object {$_ -replace "Record Name . . . . . :", ""}
I'm making a reversi game in c++ and whenever I use a 10 by 10 array and search within the array to switch letters the game likes to switch up my rows and columns. This output would cause the o to switch to an x.
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . x o
x . . . . . . . . .