When reading from a file using getline() spaces appear between each character? - c++

I am designing a program that takes a directory list using "dir > music.txt". My goal is to remove the permissions and the date from the file and alphabetize the list of artists. When using "getline(file, input), spaces appear between each character when the "input" variable is sent to the screen. Here is the code:
#include "stdafx.h"
using namespace std;
void AlphaSort(string (&data)[300], int size);
void PrintArray(string(&data)[300]);
// This program will read in an array, the program will then remove any text
// that is before 59 characters, then the program will remove any spaces that
// are not succeeded by letters.
int main()
{
fstream file;
string input;
string data[300];
file.open("music.txt");
while (getline(file, input))
{
cout << input << endl;
// Scroll through the entire file. Copy the lines into memory
for (int i = 0; i <= input.length() - 1; i++)
{
// Process input here...
}
}
// The array has been loaded into memory, run the sort
//AlphaSort(data, 300);
//PrintArray(data);
return 0;
}
Below is sample of the output:
d - - - - - 8 / 7 / 2 0 1 7 1 1 : 1 5 A M E i f f e l 6 5
d - - - - - 8 / 7 / 2 0 1 7 1 1 : 1 9 A M O n e R e p u b l i c
d - - - - - 8 / 7 / 2 0 1 7 1 1 : 1 8 A M M a r o o n 5
d - - - - - 8 / 7 / 2 0 1 7 1 1 : 1 8 A M L u m i n e e r s
d - - - - - 8 / 7 / 2 0 1 7 1 1 : 1 8 A M M y C h e m i c a l R o m a n c e
d - - - - - 8 / 7 / 2 0 1 7 1 1 : 1 4 A M B o b M a r l e y
d - - - - - 8 / 7 / 2 0 1 7 1 1 : 1 9 A M P a r a m o r e
d - - - - - 8 / 7 / 2 0 1 7 1 1 : 1 7 A M I n c u b u s
d - - - - - 8 / 7 / 2 0 1 7 1 1 : 1 4 A M C a r p e n t e r s
d - - - - - 8 / 7 / 2 0 1 7 1 1 : 1 5 A M F a i t h N o M o r e
d - - - - - 8 / 7 / 2 0 1 7 1 1 : 1 2 A M B a s t i l l e
d - - - - - 8 / 7 / 2 0 1 7 1 1 : 1 6 A M F r a n k i e G o e s T o H o l l y w o o d
d - - - - - 8 / 7 / 2 0 1 7 1 1 : 1 7 A M H o o b a s t a n k
As you can see, there are spaces included between each character.I have been looking at this for the past hour. I there a more "correct" way to input from a file? Below is the input file that does not contain spaces between each character:
d----- 8/7/2017 11:15 AM Eiffel 65
d----- 8/7/2017 11:19 AM One Republic
d----- 8/7/2017 11:18 AM Maroon 5
d----- 8/7/2017 11:18 AM Lumineers
d----- 8/7/2017 11:18 AM My Chemical Romance
d----- 8/7/2017 11:14 AM Bob Marley
d----- 8/7/2017 11:19 AM Paramore
d----- 8/7/2017 11:17 AM Incubus
d----- 8/7/2017 11:14 AM Carpenters
d----- 8/7/2017 11:15 AM Faith No More
d----- 8/7/2017 11:12 AM Bastille
d----- 8/7/2017 11:16 AM Frankie Goes To Hollywood
d----- 8/7/2017 11:17 AM Hoobastank
d----- 8/7/2017 11:21 AM Young The Giant
d----- 8/7/2017 11:15 AM Disturbed
d----- 8/7/2017 11:12 AM Authority Zero

I am designing a program that takes a directory list using "dir > music.txt".
Don't. If you want to work with the directory contents, work with it directly.
My goal is to remove the permissions and the date from the file and alphabetize the list of artists.
If you wouldn't use dir, you wouldn't have permissions and date information listed.
Also, C++ is not a good tool to use for this task. You seem to be on Windows, so try writing a PowerShell script, or if you have Unix-ish tools installed, bash. It should be pretty simple.

Related

How to match leading and trailing hyphen

I have a Pandas dataframe with decimal values like below.
'+' and '-' signs can either be leading or trailing.
df = pd.DataFrame({'amt': ['11.11', '+22.22', '33.33+', '-44.44', '55.55-', '66.66', '77.77', '8a8', '99', '97-9']})
df['amt']
0 11.11
1 +22.22
2 33.33+
3 -44.44
4 55.55-
5 66.66
6 77.77
7 8a8
8 99
9 97-9
Name: amt, dtype: object
My requirement is to:
Remove leading and trailing '+'
Move trailing '-' to leading '-'
This is what I have done so far:
abs_ser = pd.to_numeric(df['amt'].str.strip().str.strip('+|-'), errors='coerce')
abs_ser
0 11.11
1 22.22
2 33.33
3 44.44
4 55.55
5 66.66
6 77.77
7 NaN
8 99.00
9 NaN
Name: amt, dtype: float64
df['clean_amt'] = np.where(df['amt'].str.match(r'(^-|-$)'), abs_ser * -1, abs_ser)
df[['amt', 'clean_amt']]
amt clean_amt
0 11.11 11.11
1 +22.22 22.22
2 33.33+ 33.33
3 -44.44 -44.44
4 55.55- 55.55
5 66.66 66.66
6 77.77 77.77
7 8a8 NaN
8 99 99.00
9 97-9 NaN
The regular expression is not matching the trailing '-'.
Can someone help with correcting the regular expression?
I have tried the following and it gives me the desired result. However, I prefer the regex if it can do it in one pass of 'amt' column.
df['clean_amt'] = np.where((df['amt'].str.startswith('-') | df['amt'].str.endswith('-')), abs_ser * -1, abs_ser)
You can use
abs_ser = pd.to_numeric(df['amt'].str.strip().str.replace(r'^\+|\+$|^(.+)(-)$', r'\2\1'), errors='coerce')
See the regex demo.
Details
^\+ - finds a + at the start
\+$ - finds a + at the end
^(.+)(-)$ - captures any one or more chars at the start of the string (capturing the text into Group 1) and then captures a - at the end of the string into Group 2.
The replacement is the concatenated Group 2 and 1 values.
You could do the following:
# strip +
df['amt'] = df['amt'].str.strip('+')
# move -
mask = df['amt'].str.contains('-$')
df.loc[mask, 'amt'] = '-' + df.loc[mask, 'amt'].str.rstrip('-')
# transform to numeric
res = pd.to_numeric(df['amt'], errors='coerce')
print(res)
Output
0 11.11
1 22.22
2 33.33
3 -44.44
4 -55.55
5 66.66
6 77.77
7 NaN
8 99.00
9 NaN
Name: amt, dtype: float64

Populating new variable using vlookup with multiple criteria in another variable

1) A new variable should be created for each unique observation listed in variable sku, which contains repeated values.
2) These newly created variables should be assigned the value of own product's price at the store/week level, as long as observations' sku value is in the same subcategory (subc) as the variable itself. For example, in eta2,3, observations in line 3, 4, and 5 have the same value because they all belong to the same subcategory as sku #3. [eta2,3 indicates sku 3, subc 2.]
3) x indicates that this is the original value for the product/subcategory that is currently being replicated.
4) If an observation doesn't belong to the same subcategory, it should reflect "0".
Orange is the given data. In green are the values from the steps 1, 2, and 3. White cells are step 4.
I am unable to offer a solution of my own, as searching for a
way to generate a variable using existing observations hasn't given me results.
I also understand that it must be a combination of forvalues, foreach, and levelsof commands?
clear
input units price sku week store subc
3 4.3 1 1 1 1
2 3 2 1 1 1
1 2.5 3 1 1 2
4 12 5 1 1 2
5 12 6 1 1 3
35 4.3 1 1 2 1
23 3 2 1 2 1
12 2.5 3 1 2 2
35 12 5 1 2 2
35 12 6 1 2 3
3 20 1 2 1 1
2 30 2 2 1 1
4 40 3 2 2 2
1 50 4 2 2 2
9 10 5 2 2 2
2 90 6 2 2 3
end
UPDATE
Based on Nick Cox' feedback, this is the final code that gives the result I have been looking for:
clear
input units price sku week store subc
35 4.3 1 1 1 1
23 3 2 1 1 1
12 2.5 3 1 1 2
10 1 4 1 1 2
35 12 5 1 1 2
35 12 6 1 1 3
35 5.3 1 2 1 1
23 4 2 2 1 1
12 3.5 3 2 1 2
10 2 4 2 1 2
35 13 5 2 1 2
35 13 6 2 1 3
end
egen joint = group(subc sku), label
bysort store week : gen freq = _N
su freq, meanonly
local jmax = r(max)
drop freq
tostring subc sku, replace
gen new = subc + "_"+sku
su joint, meanonly
forval j = 1/`r(max)'{
local J = new[`j']
gen eta`J' = .
}
sort subc week store sku
egen joint1 = group(subc week store), label
gen long id = _n
su joint1, meanonly
quietly forval i = 1/`r(max)' {
su id if joint1 == `i', meanonly
local jmin = r(min)
local jmax = r(max)
forval j = `jmin'/`jmax' {
local subc = subc[`j']
local sku = sku[`j']
replace eta`subc'_`sku' = price[`j'] in `jmin'/`jmax'
replace eta`subc'_`sku' = 0 in `j'/`j'
}
}
I worry on your behalf that in a dataset of any size what you ask for would mean many, many extra variables. I wonder on your behalf whether you need all of them any way for whatever you want to do with them.
That aside, this seems to be what you want. Naturally your column headers in your spreadsheet view aren't legal variable names. Disclosure: despite being the original author of levelsof I wouldn't prefer its use here.
clear
input units price sku week store subc
35 4.3 1 1 1 1
23 3 2 1 1 1
12 2.5 3 1 1 2
10 1 4 1 1 2
35 12 5 1 1 2
35 12 6 1 1 3
end
sort subc sku
* subc identifiers guaranteed to be integers 1 up
egen subc_id = group(subc), label
* observation numbers in a variable
gen long id = _n
* how many subc? loop over the range
su subc_id, meanonly
forval i = 1/`r(max)' {
* which subc is this one? look it up using -summarize-
* assuming that subc is numeric!
su subc if subc_id == `i', meanonly
local I = r(min)
* which observation numbers for this subc?
* given the prior sort, they are all contiguous
su id if subc_id == `i', meanonly
* for each observation in the subc, find out the sku and copy its price
* to all observations in that subc
forval j = `r(min)'/`r(max)' {
local J = sku[`j']
gen eta_`I'_`J' = cond(subc_id == `i', price[`j'], 0)
}
}
list subc eta*, sepby(subc)
+------------------------------------------------------------------+
| subc eta_1_1 eta_1_2 eta_2_3 eta_2_4 eta_2_5 eta_3_6 |
|------------------------------------------------------------------|
1. | 1 4.3 3 0 0 0 0 |
2. | 1 4.3 3 0 0 0 0 |
|------------------------------------------------------------------|
3. | 2 0 0 2.5 1 12 0 |
4. | 2 0 0 2.5 1 12 0 |
5. | 2 0 0 2.5 1 12 0 |
|------------------------------------------------------------------|
6. | 3 0 0 0 0 0 12 |
+------------------------------------------------------------------+
Notes:
N1. In your example, subc is numbered 1, 2, etc. My extra variable subc_id ensures that to be true even if in your real data the identifiers are not so clean.
N2. The expression
cond(subc_id == `i', price[`j'], 0)
could also be
(subc_id == `i') * price[`j']
N3. It seems possible that a different data structure would be much more efficient.
EDIT: Here is code and results for another data structure.
clear
input units price sku week store subc
35 4.3 1 1 1 1
23 3 2 1 1 1
12 2.5 3 1 1 2
10 1 4 1 1 2
35 12 5 1 1 2
35 12 6 1 1 3
end
sort subc sku
egen subc_id = group(subc), label
bysort subc : gen freq = _N
su freq, meanonly
local jmax = r(max)
drop freq
forval j = 1/`jmax' {
gen eta`j' = .
gen which`j' = .
}
gen long id = _n
su subc_id, meanonly
quietly forval i = 1/`r(max)' {
su id if subc_id == `i', meanonly
local jmin = r(min)
local jmax = r(max)
local k = 1
forval j = `jmin'/`jmax' {
replace which`k' = sku[`j'] in `jmin'/`jmax'
replace eta`k' = price[`j'] in `jmin'/`jmax'
local ++k
}
}
list subc sku *1 *2 *3 , sepby(subc)
+------------------------------------------------------------+
| subc sku eta1 which1 eta2 which2 eta3 which3 |
|------------------------------------------------------------|
1. | 1 1 4.3 1 3 2 . . |
2. | 1 2 4.3 1 3 2 . . |
|------------------------------------------------------------|
3. | 2 3 2.5 3 1 4 12 5 |
4. | 2 4 2.5 3 1 4 12 5 |
5. | 2 5 2.5 3 1 4 12 5 |
|------------------------------------------------------------|
6. | 3 6 12 6 . . . . |
+------------------------------------------------------------+
I am adding another answer that tackles combinations of subc and week. Previous discussion establishes that what you are trying to do would add an extra variable for every observation. This can't be a good idea! At best, you might just have many new variables, mostly zeros. At worst, you will run into Stata's limits.
Hence I won't support your endeavour to go further down the same road, but show how the second data structure I discuss in my previous answer can be produced. Indeed, you haven't indicated (a) why you want all these variables, which are just the existing data redistributed; (b) what your strategy is for dealing with them; (c) why rangestat (SSC) or some other program could not remove the need to create them in the first place.
clear
input units price sku week store subc
35 4.3 1 1 1 1
23 3 2 1 1 1
12 2.5 3 1 1 2
10 1 4 1 1 2
35 12 5 1 1 2
35 12 6 1 1 3
35 5.3 1 2 1 1
23 4 2 2 1 1
12 3.5 3 2 1 2
10 2 4 2 1 2
35 13 5 2 1 2
35 13 6 2 1 3
end
sort subc week sku
egen joint = group(subc week), label
bysort joint : gen freq = _N
su freq, meanonly
local jmax = r(max)
drop freq
forval j = 1/`jmax' {
gen eta`j' = .
gen which`j' = .
}
gen long id = _n
su joint, meanonly
quietly forval i = 1/`r(max)' {
su id if joint == `i', meanonly
local jmin = r(min)
local jmax = r(max)
local k = 1
forval j = `jmin'/`jmax' {
replace which`k' = sku[`j'] in `jmin'/`jmax'
replace eta`k' = price[`j'] in `jmin'/`jmax'
local ++k
}
}
list subc week sku *1 *2 *3 , sepby(subc week)
+-------------------------------------------------------------------+
| subc week sku eta1 which1 eta2 which2 eta3 which3 |
|-------------------------------------------------------------------|
1. | 1 1 1 4.3 1 3 2 . . |
2. | 1 1 2 4.3 1 3 2 . . |
|-------------------------------------------------------------------|
3. | 1 2 1 5.3 1 4 2 . . |
4. | 1 2 2 5.3 1 4 2 . . |
|-------------------------------------------------------------------|
5. | 2 1 3 2.5 3 1 4 12 5 |
6. | 2 1 4 2.5 3 1 4 12 5 |
7. | 2 1 5 2.5 3 1 4 12 5 |
|-------------------------------------------------------------------|
8. | 2 2 3 3.5 3 2 4 13 5 |
9. | 2 2 4 3.5 3 2 4 13 5 |
10. | 2 2 5 3.5 3 2 4 13 5 |
|-------------------------------------------------------------------|
11. | 3 1 6 12 6 . . . . |
|-------------------------------------------------------------------|
12. | 3 2 6 13 6 . . . . |
+-------------------------------------------------------------------+
clear
input units price sku week store subc
35 4.3 1 1 1 1
23 3 2 1 1 1
12 2.5 3 1 1 2
10 1 4 1 1 2
35 12 5 1 1 2
35 12 6 1 1 3
35 5.3 1 2 1 1
23 4 2 2 1 1
12 3.5 3 2 1 2
10 2 4 2 1 2
35 13 5 2 1 2
35 13 6 2 1 3
end
egen joint = group(subc sku), label
bysort store week : gen freq = _N
su freq, meanonly
local jmax = r(max)
drop freq
tostring subc sku, replace
gen new = subc + "_"+sku
su joint, meanonly
forval j = 1/`r(max)'{
local J = new[`j']
gen eta`J' = .
}
sort subc week store sku
egen joint1 = group(subc week store), label
gen long id = _n
su joint1, meanonly
quietly forval i = 1/`r(max)' {
su id if joint1 == `i', meanonly
local jmin = r(min)
local jmax = r(max)
forval j = `jmin'/`jmax' {
local subc = subc[`j']
local sku = sku[`j']
replace eta`subc'_`sku' = price[`j'] in `jmin'/`jmax'
replace eta`subc'_`sku' = 0 in `j'/`j'
}
}
list subc sku store week eta*, sepby(subc)
+---------------------------------------------------------------------------------+
| store week subc sku eta1_1 eta1_2 eta2_3 eta2_4 eta2_5 eta3_6 |
|---------------------------------------------------------------------------------|
1. | 1 1 1 2 4.3 0 . . . . |
2. | 1 1 1 1 0 3 . . . . |
|---------------------------------------------------------------------------------|
3. | 1 1 2 4 . . 2.5 0 12 . |
4. | 1 1 2 3 . . 0 1 12 . |
5. | 1 1 2 5 . . 2.5 1 0 . |
|---------------------------------------------------------------------------------|
6. | 1 1 3 6 . . . . . 0 |
|---------------------------------------------------------------------------------|
7. | 1 2 1 2 5.3 0 . . . . |
8. | 1 2 1 1 0 4 . . . . |
|---------------------------------------------------------------------------------|
9. | 1 2 2 3 . . 0 2 13 . |
10. | 1 2 2 5 . . 3.5 2 0 . |
11. | 1 2 2 4 . . 3.5 0 13 . |
|---------------------------------------------------------------------------------|
12. | 1 2 3 6 . . . . . 0 |
+---------------------------------------------------------------------------------+

how to use _infile_ in SAS to delete lines in a hierarchical prog

Trying a hierarchical prg in SAS Studio
I'm trying to retain the Buyer code and Vendor with a retain statement as "headers" and read in the detail with a if/then conditional statements, but cannot figure out a way to do this with the repeating labels in the way. How can I use infile to delete the repeating/imbedded labels?
oucher Vendor Vendor Payment Po Nb Total Total PO Inv
Nbr I nv Nbr/Ln Inv Dat e Due Date Inv Amt Ln Nb Rec'd Dist Inv'd Price Price St
------------ ---------- --- ----------- ----------- -------------- -------- - --------------- -------- --------- -------------- ------------ ---
Buyer Code: BLS BETTIE SM ITH
Vendor: 8444 DAT EX- OHMEDA
762100 62245094 / 03/04/15 42097 2142.46 264568 P
1 Las t Recvd Dat e: 12/19/14 1 7 7 1 3971.88 2142.46 Q
762101 62243752 / 03/01/15 42094 16001.6 264568 P
1 Las t Recvd Dat e: 12/19/14 1 7 7 1 3971.88 16001.6 B
762690 62247150 / 03/07/15 42100 1790.38 264568 P
1 Las t Recvd Dat e: 12/19/14 1 7 7 1 3971.88 1790.38 Q
762691 62246387 / 03/06/15 42099 1520.38 264568 P
1 Las t Recvd Dat e: 12/19/14 1 7 7 1 3971.88 1520.38 Q
762692 62246386 / 03/06/15 42099 1070.38 264568 P
1 Las t Recvd Dat e: 12/19/14 1 7 7 1 3971.88 1070.38 Q
762693 62246385 / 03/06/15 42099 1075.19 264568 P
1 Las t Recvd Dat e: 12/19/14 1 7 7 1 3971.88 1075.19 Q
762694 62246384 / 03/06/15 42099 1115.38 264568 P
1 Las t Recvd Dat e: 12/19/14 1 7 7 1 3971.88 1115.38 Q
763572 62253066 / 03/18/15 42111 890.38 264568 P
1 Las t Recvd Dat e: 12/19/14 1 7 7 1 3971.88 890.38 Q
763574 62253064 / 03/18/15 42111 540 264568 P
1 Las t Recvd Dat e: 12/19/14 1 7 7 1 3971.88 540 Q
763805 62255278 / 03/21/15 42114 1520.38 264568 P
1 Las t Recvd Dat e: 12/19/14 1 7 7 1 3971.88 1520.38 Q
764809 62260713 / 04/01/15 42125 8190.48 264568 P
1 Las t Recvd Dat e: 12/19/14 1 7 7 1 3971.88 3971.88 Q
2 Las t Recvd Dat e: 12/19/14 2 7 7 1 3740 3740 Q
3 Las t Recvd Dat e: 12/19/14 3 7 7 1 478.59 478.6 Q
765293 62257450 / 03/26/15 42119 540 264568 P
1 Las t Recvd Dat e: 6 1 574.31 540 Q
765294 62257449 / 03/26/15 42119 720 264568 P
1 Las t Recvd Dat e: 6 1 574.31 720 B
Date: 05/01/ 2015 ST. B ARNABAS O SPITAL P age : 2
Time: 8:47am Pay ables Status E xception R pt For 05/01/20 15 R eport: GARPS ESB
Voucher Vendor Vendor Payment Po Nb Total Total PO Inv
Nbr I nv Nbr/Ln Inv Dat e Due Date Inv Amt Ln Nb Rec'd Dist Inv'd Price Price St
------------ ---------- --- ----------- ----------- -------------- -------- - --------------- -------- ---------
Code:
libname niklib '/home/nyioves/Nikfold/';
data myfile4 (drop=checkpt);
length Checkpt $ 5. Vendor $ 30.;
infile '/home/nyioves/Nikfold/Invoice.txt' missover obs=35;
retain Code1 BuyerID Vendor;
input Checkpt $ #;
if Checkpt="Buyer" then input Code1 $ BuyerID & $40.;
if Checkpt="Vendor" then input Vendor : $30.;
else if VoucherNo $ Invno $ seperator $ Vndinvdate mmddyy10. PaymntDue $ InvAmt $ PONum Status1 $ /
num1 Las $ letter $ Recvd $ dat $ echar $ date1 $ nnmbr $ totRecd $ totdist invd
poprice invprice st2 $;
run;
So I think you're trying to do something like the below.
Note the use of the double # symbol. That line of code will read in the input into a temporary variable called _infile_. The double # symbol will prevent the input cursor from progressing. This lets us 'look ahead' to see what the line contains before we decide how we want to process it.
Also notice that we read in the buyer and vendor, and retain the values, but we don't output the observation on these lines, we wait for the regular 'transaction' type lines to output.
If it's a line that we want to ignore - ie. the labels, we simply issue another input statement to move the input cursor forward to the next line.
EDIT: I should also mention that the =: operator is similar to a 'begins-with' operator. It truncates both strings either side of the operator to the shortest string length and then performs an equality check.
data test;
length buyer_code vendor $200;
retain buyer_code vendor '';
infile datalines truncover ;
input ##;
if not (_infile_ =: 'Date:')
and not (_infile_ =: 'Time:')
and not (_infile_ =: 'Voucher')
and not (_infile_ =: 'Nbr I')
and not (_infile_ =: '-------')
then do;
if _infile_ =: 'Buyer Code' then do;
buyer_code = cats(scan(_infile_,2,':'));
input;
end;
else if _infile_ =: 'Vendor:' then do;
vendor = cats(scan(_infile_,2,':'));
input;
end;
else do;
/* REPLACE THESE 2 LINES WITH YOUR INPUT STATEMENT TO INPUT OTHER VARIABLES */
input ;
x = _infile_;
output;
end;
end;
else do;
input; * MOVE INPUT CURSOR TO NEXT LINE WITHOUT ASSIGNING ANYTHING;
end;
datalines;
Buyer Code: BLS BETTIE SM ITH
Vendor: 8444 DAT EX- OHMEDA
762100 62245094 / 03/04/15 42097 2142.46 264568 P
1 Las t Recvd Dat e: 12/19/14 1 7 7 1 3971.88 2142.46 Q
762101 62243752 / 03/01/15 42094 16001.6 264568 P
1 Las t Recvd Dat e: 12/19/14 1 7 7 1 3971.88 16001.6 B
762690 62247150 / 03/07/15 42100 1790.38 264568 P
1 Las t Recvd Dat e: 12/19/14 1 7 7 1 3971.88 1790.38 Q
762691 62246387 / 03/06/15 42099 1520.38 264568 P
1 Las t Recvd Dat e: 12/19/14 1 7 7 1 3971.88 1520.38 Q
762692 62246386 / 03/06/15 42099 1070.38 264568 P
1 Las t Recvd Dat e: 12/19/14 1 7 7 1 3971.88 1070.38 Q
762693 62246385 / 03/06/15 42099 1075.19 264568 P
1 Las t Recvd Dat e: 12/19/14 1 7 7 1 3971.88 1075.19 Q
762694 62246384 / 03/06/15 42099 1115.38 264568 P
1 Las t Recvd Dat e: 12/19/14 1 7 7 1 3971.88 1115.38 Q
763572 62253066 / 03/18/15 42111 890.38 264568 P
1 Las t Recvd Dat e: 12/19/14 1 7 7 1 3971.88 890.38 Q
763574 62253064 / 03/18/15 42111 540 264568 P
1 Las t Recvd Dat e: 12/19/14 1 7 7 1 3971.88 540 Q
763805 62255278 / 03/21/15 42114 1520.38 264568 P
1 Las t Recvd Dat e: 12/19/14 1 7 7 1 3971.88 1520.38 Q
764809 62260713 / 04/01/15 42125 8190.48 264568 P
1 Las t Recvd Dat e: 12/19/14 1 7 7 1 3971.88 3971.88 Q
2 Las t Recvd Dat e: 12/19/14 2 7 7 1 3740 3740 Q
3 Las t Recvd Dat e: 12/19/14 3 7 7 1 478.59 478.6 Q
765293 62257450 / 03/26/15 42119 540 264568 P
1 Las t Recvd Dat e: 6 1 574.31 540 Q
765294 62257449 / 03/26/15 42119 720 264568 P
1 Las t Recvd Dat e: 6 1 574.31 720 B
Date: 05/01/ 2015 ST. B ARNABAS O SPITAL P age : 2
Time: 8:47am Pay ables Status E xception R pt For 05/01/20 15 R eport: GARPS ESB
Voucher Vendor Vendor Payment Po Nb Total Total PO Inv
Nbr I nv Nbr/Ln Inv Dat e Due Date Inv Amt Ln Nb Rec'd Dist Inv'd Price Price St
------------ ---------- --- ----------- ----------- -------------- -------- - --------------- -------- ---------
;
run;

using get() and appending those chars to a string is giving me nonsense

I am supposed to use a program that (one char at a time) reads a GPS log file, and parses it. I'm getting normal responses when I use some .log files, and not with others (especially not long ones).
The code that grabs the information and stores it is below:
class ReadInput{
public:
string massiveString;
};
void ReadInput::assign(string inMassiveString){ //assign the string passed to it to the object
this->massiveString.empty(); //clear whatever might be in the string
this->massiveString=inMassiveString; //copy the string into where it belongs.
}
int main(int argc, const char * argv[]) {
ifstream inputStream;
inputStream.open("gps3.log");
int i = 1;
char temp;
string tempString;
ReadInput *sentence[258];
//this is the part that grabs the characters
while(1){ //
if (!inputStream.eof()){ //
inputStream.get(temp);
if (temp!=' ') {
tempString.append(&temp); //this appends the characters to a temporary string
// cout << i << "\t" << tempString << endl; //testing the input
}
if (temp == '\n') { //if this is the end of the line, pass it on.
sentence[i]=new ReadInput;
sentence[i]->assign(tempString); //the part that copies the temporary string to the object
cout << i << "\t" << sentence[i]->massiveString << endl; //another testing line
i++;
tempString.clear();
}
}
else{
break;
}
}
}
it is very important that I read it character by character.
what it should be reading looks like this:
$GPGGA,155008.000,3732.7239,N,07726.9956,W,1,05,1.7,89.0,M,-33.6,M,,0000*53
and here is an example of a problematic reading. in the format of
entry#, stringStoredInEntry.
1 $GPGGA,155002.000,3732.7239,N,07726.9956,W,1,05,1.7,89.1,M,-33.6,M,,0000*58
2 $GPGSA,A,3,17,06,28,02,24,,,,,,,,3.2,1.7,2.7*3E
3 $GPRMC,155002.000,A,3732.7239,N,07726.9956,W,0.00,80.30,141014,,,A*48
4 $GPGGA,155003.000,3732.7239,N,07726.9956,W,1,05,1.7,89.1,M,-33.6,M,,0000*59
5 $GPGSA,A,3,17,06,28,02,24,,,,,,,,3.2,1.7,2.7*3E
6 $GPGSV,3,1,12,17,64,038,42,06,63,250,43,28,44,150,45,02,25,239,38*7B
7 $GPGSV,3,2,12,24,17,294,22,10,21,176,22,12,25,316,23,51,36,223,37*71
8 F
9 $ G P R M C , 1 5 5 0 0 3 . 0 0 0 , A , 3 79
10 $
G
P
G
G
A
,
1
5
5
0
0
4
.
0
0
0
,
3
7
3
2
.
7
2
3
9
,
N
,
0
7
7
2
6
.
9
9
5
6
,
W
,
1
,
0
5
,
1
.
7
,
8
9
.
1
,
M
,
-
3
3
.
6
,
M
,
,
0
0
0
0
*
5
E
11 $
G
P
G
S
A
,
A
,
3
,
1
7
,
0
6
,
2
8
,
0
2
,
2
4
,
,
,
,
,
,
,
,
3
.
2
,
1
.
7
,
2
.
7
*
3
E
12 $
G
P
R
M
C
,
1
5
5
0
0
4
.
0
0
0
,
A
,
3
7
3
2
.
7
2
3
9
,
N
,
0
7
7
2
6
.
9
8 $GPGGA,155009.000,3732.7239,N,07726.9956,W,1,05,1.7,89.0,M,-33.6,M,,0000*52
29 $GPGSA,A,3,17,06,28,02,24,,,,,,,,3.2,1.7,2.7*3E
30 $GPRMC,155009.000,A,3732.7239,N,07726.9956,W,0.00,80.30,141014,,,A*43
31 $GPGGA,155010.000,3732.7239,N,07726.9956,W,1,05,1.7,89.0,M,-33.6,M,,0000*5A
2 $ G P G S A , A , 3 , 1 7 , 0 6 , 2 8 , 0 2 , 2 4 , , , , , , , , 3 . 2 , 1 . 7 , 2 . 7 * 3 E
!33 $!G!P!R!M!C!,!1!5!5!0!1!0!.!0!0!0!,!A!,!3!7!3!2!.!7!2!3!9!,!N!,!0!7!7!2!6!.!9!9!5!6!,!W!,!0!.!0!0!,!8!0!.!3!0!,!1!4!1!0!1!4!,!,!,!A!*!4!B!
"34 $"G"P"G"G"A","1"5"5"0"1"1"."0"0"0","3"7"3"2"."7"2"3"9","N","0"7"7"2"6"."9"9"5"6","W","1","0"5","1"."7","8"9"."0","M","-"3"3"."6","M",","0"0"0"0"*"5"B"
#35 $#G#P#G#S#A#,#A#,#3#,#1#7#,#0#6#,#2#8#,#0#2#,#2#4#,#,#,#,#,#,#,#,#3#.#2#,#1#.#7#,#2#.#7#*#3#E#
$36 $$G$P$R$M$C$,$1$5$5$0$1$1$.$0$0$0$,$A$,$3$7$3$2$.$7$2$3$9$,$N$,$0$7$7$2$6$.$9$9$5$6$,$W$,$0$.$0$0$,$8$0$.$3$0$,$1$4$1$0$1$4$,$,$,$A$*$4$A$
%37 $%G%P%G%G%A%,%1%5%5%0%1%2%.%0%0%0%,%3%7%3%2%.%7%2%3%9%,%N%,%0%7%7%2%6%.%9%9%5%6%,%W%,%1%,%0%5%,%1%.%7%,%8%9%.%0%,%M%,%-%3%3%.%6%,%M%,%,%0%0%0%0%*%5%8%
&38 $&G&P&G&S&A&,&A&,&3&,&1&7&,&0&6&,&2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...9.9.5.6.,.W.,.1.,.0.5.,.1...7.,.8.9...0.,.M.,.-.3.3...6.,.M.,.,.0.0.0.0.*.5.E.
/47 $/G/P/G/S/A/,/A/,/3/,/1/7/,/0/6/,/2/8/,/0/2/,/2/4/,/,/,/,/,/,/,/,/3/./2/,/1/./7/,/2/./7/*/3/E/
048 $0G0P0R0M0C0,0105050001040.0000000,0A0,030703020.070203090,0N0,00070702060.090905060,0W0,000.00000,08000.03000,0104010001040,0,0,0A0*040F0
149 $1G1P1G1G1A1,1115151011151.1010101,131713121.171213191,1N1,10171712161.191915161,1W1,111,10151,111.171,18191.101,1M1,1-13131.161,1M1,1,101010101*151F1
250 $2G2P2G2S2A2,2A2,232,21272,20262,22282,20222,22242,2,2,2,2,2,2,2,232.222,212.272,222.272*232E2
351 $3G3P3R3M3C3,3135353031353.3030303,3A3,333733323.373233393,3N3,30373732363.393935363,3W3,303.30303,38303.33303,3134313031343,3,3,3A3*343E3
452 $4G4P4G4G4A4,4145454041464.4040404,434743424.474243494,4N4,40474742464.494945464,4W4,414,40454,414.474,48484.494,4M4,4-43434.464,4M4,4,404040404*45444
553 $5G5P5G5S5A5,5A5,535,51575,50565,52585,50525,52545,5,5,5,5,5,5,5,535.525,515.575,525.575*535E5
654 $6G6P6R6M6C6,6165656061666.6060606,6A6,636763626.676263696,6N6,60676762666.696965666,6W6,606.60606,68606.63606,6164616061646,6,6,6A6*646D6
755 $7G7P7G7G7A7,7175757071777.7070707,737773727.777273797,7N7,70777772767.797975767,7W7,717,70757,717.777,78787.797,7M7,7-73737.767,7M7,7,707070707*75757
856 $8G8P8G8S8A8,8A8,838,81878,80868,82888,80828,82848,8,8,8,8,8,8,8,838.828,818.878,828.878*838E8
957 $9G9P9R9M9C9,9195959091979.9090909,9A9,939793929.979293999,9N9,90979792969.999995969,9W9,909.90909,98909.93909,9194919091949,9,9,9A9*949C9
:58 $:G:P:G:G:A:,:1:5:5:0:1:8:.:0:0:0:,:3:7:3:2:.:7:2:3:9:,:N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AB,B3B7B3B2B.B7B2B3B9B,BNB,B0B7B7B2B6B.B9B9B5B6B,BWB,B0B.B0B0B,B8B0B.B3B0B,B1B4B1B0B1B4B,B,B,BAB*B4B2B
B67 $GPGGA,155007.000,3732.7239,N,07726.9956,W,1,05,1.7,89.0,M,-33.6,M,,0000*5C
C1 $GPGGA,155002.000,3732.7239,N,07726.9956,W,1,05,1.7,89.1,M,-33.6,M,,0000*58
21 $GPRMC,155007.000,A,3732.7239,N,07726.9956,W,0.00,80.30,141014,,,A*4D
22 $GPGSA,A,3,17,06,28,02,24,,,,,,,,3.2,1.7,2.7*3E,1.7,89.0,M,-33.6,M,,0000*53
23 $GPGSA,A,3,17,06,28,02,24,,,,,,,,3.2,1.7,2.7*3E
34 $GPRMC,155002.000,A,3732.7239,N,07726.9956,W,0.00,80.30,141014,,,A*48
25 $GPGSV,3,2,12,24,17,294,22,10,21,176,22,12,25,316,24,51,36,223,35*74
46 $GPGGA,155003.000,3732.7239,N,07726.9956,W,1,05,1.7,89.1,M,-33.6,M,,0000*59
27 $
5 $GPGSA,A,3,17,06,28,02,24,,,,,,,,3.2,1.7,2.7*3E
6 $GPGSV,3,1,12,17,64,038,42,06,63,250,43,28,44,150,45,02,25,239,38*7B
7 $GPGSV,3,2,12,24,17,294,22,10,21,176,22,12,25,316,23,51,36,223,37*71
8 F
9 $ G P R M C , 1 5 5 0 0 3 . 0 0 0 , A , 3 79
10 $
G
P
G
G
A
,
1
5
5
0
0
4
.
0
0
0
,
3
7
3
2
.
7
2
3
9
,
N
,
0
7
7
2
6
.
9
9
5
6
,
W
,
1
,
0
5
,
1
.
7
,
8
9
.
1
,
M
,
-
3
3
.
6
,
M
,
,
0
0
0
0
*
5
E
11 $
G
P
G
S
A
,
A
,
3
,
1
7
,
0
6
,
2
8
,
0
2
,
2
4
,
,
,
,
,
,
,
,
3
.
2
,
1
.
7
,
2
.
7
*
3
E
12 $
G
P
R
M
C
,
1
5
5
0
0
4
.
0
0
0
,
A
,
3
7
3
2
.
7
2
3
9
,
N
,
0
7
7
2
6
.
9
9
5
6
,
W
,
0
.
0
0
,
8
0
.
3
0
8 $GPGGA,155009.000,3732.7239,N,07726.9956,W,1,05,1.7,89.0,M,-33.6,M,,0000*52
1
29 $GPGSA,A,3,17,06,28,02,24,,,,,,,,3.2,1.7,2.7*3E 4
1
30 $GPRMC,155009.000,A,3732.7239,N,07726.9956,W,0.00,80.30,141014,,,A*43
1
31 $GPGGA,155010.000,3732.7239,N,07726.9956,W,1,05,1.7,89.0,M,-33.6,M,,0000*5A
,
2 $ G P G S A , A , 3 , 1 7 , 0 6 , 2 8 , 0 2 , 2 4 , , , , , , , , 3 . 2 , 1 . 7 , 2 . 7 * 3 E
,
!3 $!G!P!R!M!C!,!1!5!5!0!1!0!.!0!0!0!,!A!,!3!7!3!2!.!7!2!3!9!,!N!,!0!7!7!2!6!.!9!9!5!6!,!W!,!0!.!0!0!,!8!0!.!3!0!,!1!4!1!0!1!4!,!,!,!A!*!4!B!
! *
"4 $"G"P"G"G"A","1"5"5"0"1"1"."0"0"0","3"7"3"2"."7"2"3"9","N","0"7"7"2"6"."9"9"5"6","W","1","0"5","1"."7","8"9"."0","M","-"3"3"."6","M",","0"0"0"0"*"5"B"
" E
#5 $#G#P#G#S#A#,#A#,#3#,#1#7#,#0#6#,#2#8#,#0#2#,#2#4#,#,#,#,#,#,#,#,#3#.#2#,#1#.#7#,#2#.#7#*#3#E#
#
$6 $$G$P$R$M$C$,$1$5$5$0$1$1$.$0$0$0$,$A$,$3$7$3$2$.$7$2$3$9$,$N$,$0$7$7$2$6$.$9$9$5$6$,$W$,$0$.$0$0$,$8$0$.$3$0$,$1$4$1$0$1$4$,$,$,$A$*$4$A$
$
%7 $%G%P%G%G%A%,%1%5%5%0%1%2%.%0%0%0%,%3%7%3%2%.%7%2%3%9%,%N%,%0%7%7%2%6%.%9%9%5%6%,%W%,%1%,%0%5%,%1%.%7%,%8%9%.%0%,%M%,%-%3%3%.%6%,%M%,%,%0%0%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6 $.G.P.G.G.A.,.1.5.5.0.1.4...0.0.0.,.3.7.3.2...7.2.3.9.,.N.,.0.7.7.2.6...9.9.5.6.,.W.,.1.,.0.5.,.1...7.,.8.9...0.,.M.,.-.3.3...6.,.M.,.,.0.0.0.0.*.5.E.
.
/7 $/G/P/G/S/A/,/A/,/3/,/1/7/,/0/6/,/2/8/,/0/2/,/2/4/,/,/,/,/,/,/,/,/3/./2/,/1/./7/,/2/./7/*/3/E/
/
08 $0G0P0R0M0C0,0105050001040.0000000,0A0,030703020.070203090,0N0,00070702060.090905060,0W0,000.00000,08000.03000,0104010001040,0,0,0A0*040F0
0
19 $1G1P1G1G1A1,1115151011151.1010101,131713121.171213191,1N1,10171712161.191915161,1W1,111,10151,111.171,18191.101,1M1,1-13131.161,1M1,1,101010101*151F1
1
20 $2G2P2G2S2A2,2A2,232,21272,20262,22282,20222,22242,2,2,2,2,2,2,2,232.222,212.272,222.272*232E2
2
31 $3G3P3R3M3C3,3135353031353.3030303,3A3,333733323.373233393,3N3,30373732363.393935363,3W3,303.30303,38303.33303,3134313031343,3,3,3A3*343E3
3
42 $4G4P4G4G4A4,4145454041464.4040404,434743424.474243494,4N4,40474742464.494945464,4W4,414,40454,414.474,48484.494,4M4,4-43434.464,4M4,4,404040404*45444
4
53 $5G5P5G5S5A5,5A5,535,51575,50565,52585,50525,52545,5,5,5,5,5,5,5,535.525,515.575,525.575*535E5
5
64 $6G6P6R6M6C6,6165656061666.6060606,6A6,636763626.676263696,6N6,60676762666.696965666,6W6,606.60606,68606.63606,6164616061646,6,6,6A6*646D6
6
75 $7G7P7G7G7A7,7175757071777.7070707,737773727.777273797,7N7,70777772767.797975767,7W7,717,70757,717.777,78787.797,7M7,7-73737.767,7M7,7,707070707*75757
7
86 $8G8P8G8S8A8,8A8,838,81878,80868,82888,80828,82848,8,8,8,8,8,8,8,838.828,818.878,828.878*838E8
8
97 $9G9P9R9M9C9,9195959091979.9090909,9A9,939793929.979293999,9N9,90979792969.999995969,9W9,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A,A0A6A,A2A8A,A0A2A,A,A,A,A,A,A,A,A,A4A.A8A,A2A.A3A,A4A.A3A*A3A0A
A
B6 $BGBPBRBMBCB,B1B5B5B0B1B9B.B0B0B0B,BAB,B3B7B3B2B.B7B2B3B9B,BNB,B0B7B7B2B6B.B9B9B5B6B,BWB,B0B.B0B0B,B8B0B.B3B0B,B1B4B1B0B1B4B,B,B,BAB*B4B2B
B
1-7 are perfect. great.
then 8 gets weird.
and it never get's normal.
Where is this coming from? is this problems with the .log file? is this my code? where is this nonsense creeping in? and, more importantly, how is it messing with the integers to the left? How can anything consistently make an integer that nonsensical?
using tempString.push_back(temp);
instead of tempString.append(&temp);
fixed everything.

Splitting single observation into multiple observations

I have the following SAS data set:
data mydata;
LENGTH id 4.0 num 4.0 A $ 4. B $ 8. C $ 20.;
input id num A $ B $ C $;
datalines;
1 1 x yy zzzzz
2 1 x yy zzzzz
3 2 xq yyqq zzzzzqqqqq
4 1 x yy zzzzz
5 3 xqw yyqqww zzzzzqqqqqwwwww
6 1 x yy zzzzz
7 4 xqwe yyqqwwee zzzzzqqqqqwwwwweeeee
;
which looks like
mydata
-------------------
id num A B C
1 1 x yy zzzzz
2 1 x yy zzzzz
3 2 xq yyqq zzzzzqqqqq
4 1 x yy zzzzz
5 3 xqw yyqqww zzzzzqqqqqwwwww
6 1 x yy zzzzz
7 4 xqwe yyqqwwee zzzzzqqqqqwwwwweeeee
The problem is that each of the observations where num > 1 actually contains data for multiple "observations" and I would like to split it up using some logic in SAS. Here's an example for what I want to get:
mydatawanted
-------------------
id num A B C
1 1 x yy zzzzz
2 1 x yy zzzzz
3 1 x yy zzzzz
3 1 q qq qqqqq
4 1 x yy zzzzz
5 1 x yy zzzzz
5 1 q qq qqqqq
5 1 w ww wwwww
6 1 x yy zzzzz
7 1 x yy zzzzz
7 1 q qq qqqqq
7 1 w ww wwwww
7 1 e ee eeeee
Basically, if num > 1 I want to take the substring of each variable depending on its length, for each item, and then output those as new observations with num = 1. Here is what I have tried to code so far:
data mydata2(drop=i _:);
set mydata; /*use the data from the original data set */
_temp_id = id; /*create temp variables from the currently read observation */
_temp_num = num;
_temp_A = A;
_temp_B = B;
_temp_C = C;
if (_temp_num > 1) THEN /* if num in current record > 1 then split them up */
do i = 1 to _temp_num;
id = _temp_id; /* keep id the same */
num = 1; /* set num to 1 for each new observation */
A = substr(_temp_A,i,i); /*split the string by 1s */
B = substr(_temp_B,1 + 2 * (i - 1),i * 2); /*split the string by 2s */
C = substr(_temp_C,1 + 5 * (i - 1),i * 5); /*split the string by 5s */
OUTPUT; /* output this new observation with the changes */
end;
else OUTPUT; /* if num == 1 then output without any changes */
run;
However it doesn't work as I wanted it to (I put in some comments to show what I thought was happening at each step). It actually produces the following result:
mydata2
-------------------
id num A B C
1 1 x yy zzzzz
2 1 x yy zzzzz
3 1 x yy zzzzz
3 1 q qq qqqqq
4 1 x yy zzzzz
5 1 x yy zzzzz
5 1 qw qqww qqqqqwwwww
5 1 w ww wwwww
6 1 x yy zzzzz
7 1 x yy zzzzz
7 1 qw qqww qqqqqwwwww
7 1 we wwee wwwwweeeee
7 1 e ee eeeee
This mydata2 result isn't the same as mydatawanted. The lines where num = 1 are fine but when num > 1 the output records are much different from what I want. The total number of records are correct though. I'm not really sure what is happening, since this is the first time I tried any complicated SAS logic like this, but I would appreciate any help in either fixing my code or accomplishing what I want to do using any alternate methods. Thank you!
edit: I fixed a problem with my original input mydata data statement and updated the question.
Your substrings are incorrect. Substr takes the arguments (original string, start, length), not (original string, start, ending position). So length should be 1,2,5 not i,i*2,i*5.
A = substr(_temp_A,i,1); /*split the string by 1s */
B = substr(_temp_B,1 + 2 * (i - 1),2); /*split the string by 2s */
C = substr(_temp_C,1 + 5 * (i - 1),5); /*split the string by 5s */