Desktop productivity for business analysts and programmers

including quotation mark for larger string

Accepted Solution Solved
Reply
Super Contributor
Super Contributor
Posts: 340
Accepted Solution

including quotation mark for larger string

[ Edited ]

 

Hello Friends, i am referring existing big code and for one output - have two different values for one variable "file" - large string. one value has quotation mark and other doesn't as it doesn't has embedded space in between, i want to output larger string - which doesn't has qutation mark - WITH quotation mark as well - any suggestion please ....

 

have

"/abcdef-u01/11111_SASGridGAML_HDprd/xxx/sas_jobs/yyy/data/history/487623847/

20151001_bkp/abc def group report 20151010.html"

 

/abcdef-u01/11111_SASGridGAML_HDprd/xxx/sas_jobs/yyy/data/history/487623847/

20151001_bkp/report_20151010.html

 

want

"/abcdef-u01/11111_SASGridGAML_HDprd/xxx/sas_jobs/yyy/data/history/487623847/

20151001_bkp/abc def group report 20151010.html"

 

"/abcdef-u01/11111_SASGridGAML_HDprd/xxx/sas_jobs/yyy/data/history/487623847/

20151001_bkp/report_20151010.html"

 

 


Accepted Solutions
Solution
‎03-21-2017 12:40 PM
Respected Advisor
Posts: 4,137

Re: including quotation mark for larger string

[ Edited ]

@woo

Attaching representative sample data or a sub-set of real data would really help us to give you the right advise.

 

If the string with/without quotes is always at the very end of an input record like in the data you've posted then things could be quite simple.

 

Read the first 5 variables using a delimiter blank. This sets the input pointer after the last of the 5 variables (code); then read the rest of the string not using any delimiter.

data sample;
  attrib
    id size permission xx code length=$10 informat=$10.
    PathFile length=$200
    ;
  infile datalines4 dlm=' ' truncover;
  input id size permission xx code PathFile $200.;
  PathFile=dequote(PathFile);
  datalines;
123456789 1234 -rwxr-x--- 1 xyzd "/abcdef-u01/11111_SASGridGAML_HDprd/xxx/sas_jobs/yyy/data/history/487623847/20151001_bkp/abc def group report 20151010.html"
123456789 1234 -rwxr-x--- 1 xyzd  /abcdef-u01/11111_SASGridGAML_HDprd/xxx/sas_jobs/yyy/data/history/487623847/20151001_bkp/report_20151010.html
;
run;

 

View solution in original post


All Replies
PROC Star
Posts: 295

Re: including quotation mark for larger string

Assuming I understand, I think the following will do what you want, which is to quote the string if not already quoted:

 

data have;
    string = '"/abcdef-u01/11111_SASGridGAML_HDprd/xxx/sas_jobs/yyy/data/history/487623847/20151001_bkp/abc def group report 20151010.html"'; output;
    string = '/abcdef-u01/11111_SASGridGAML_HDprd/xxx/sas_jobs/yyy/data/history/487623847/20151001_bkp/report_20151010.html'; output;
run;

data want;
    set have;
    string = prxchange('s/[^"]$|^[^"]/"/i', -1, strip(string));
run;

Super Contributor
Super Contributor
Posts: 340

Re: including quotation mark for larger string

[ Edited ]

Thank you Collinelliot,


what I was thinking was reading from output file itself and then apply quotation mark to variable "files".

 

however, my challange to read below data is, since have more variables along with "files" variable (like below) need to ask sas to read continuously - in some cases have " in end and in some case its not there -

 

have

123456789 1234 -rwxr-x--- 1 xyzd "/abcdef-u01/11111_SASGridGAML_HDprd/xxx/sas_jobs/yyy/data/history/487623847/

20151001_bkp/abc def group report 20151010.html"

 

123456789 1234 -rwxr-x--- 1 xyzd  /abcdef-u01/11111_SASGridGAML_HDprd/xxx/sas_jobs/yyy/data/history/487623847/

20151001_bkp/report_20151010.html

 

so this is not working fine - may be becasue of have more than one delimiter in raw file,

 

filename xyz "/wherever_my_file_is/test.txt"; /*test.txt is what i said i have - above*/

data test;

length id $10

size $10

permission $20

code $20

files $1000;

infile xyz dsd dlm=" ";

input id size permission code files @@;

run;

Super Contributor
Super Contributor
Posts: 340

Re: including quotation mark for larger string

tried this way as well, but didn't work quite well...

 

it is reading fine variable where don't have space in between but not good for variable where have multiple space in between,,,

 

filename xyz "/wherever_my_file_is/test.txt"; /*test.txt is what i said i have - above*/

data test;

length id $10

size $10

permission $20

code $20

files $1000;

infile xyz dsd dlm=" ";

input #1 id size permission code 

      #2 files @@;

run;

Super User
Posts: 11,134

Re: including quotation mark for larger string

Try attaching a text file with a couple example lines of data that behaves like your actual data (or some of your actual data if is ot sensitive).

 

I suspect I am not the only one that is not sure what you are actually attempting read.

Solution
‎03-21-2017 12:40 PM
Respected Advisor
Posts: 4,137

Re: including quotation mark for larger string

[ Edited ]

@woo

Attaching representative sample data or a sub-set of real data would really help us to give you the right advise.

 

If the string with/without quotes is always at the very end of an input record like in the data you've posted then things could be quite simple.

 

Read the first 5 variables using a delimiter blank. This sets the input pointer after the last of the 5 variables (code); then read the rest of the string not using any delimiter.

data sample;
  attrib
    id size permission xx code length=$10 informat=$10.
    PathFile length=$200
    ;
  infile datalines4 dlm=' ' truncover;
  input id size permission xx code PathFile $200.;
  PathFile=dequote(PathFile);
  datalines;
123456789 1234 -rwxr-x--- 1 xyzd "/abcdef-u01/11111_SASGridGAML_HDprd/xxx/sas_jobs/yyy/data/history/487623847/20151001_bkp/abc def group report 20151010.html"
123456789 1234 -rwxr-x--- 1 xyzd  /abcdef-u01/11111_SASGridGAML_HDprd/xxx/sas_jobs/yyy/data/history/487623847/20151001_bkp/report_20151010.html
;
run;

 

Super User
Posts: 9,875

Re: including quotation mark for larger string

data have;
    string = '"/abcdef-u01/11111_SASGridGAML_HDprd/xxx/sas_jobs/yyy/data/history/487623847/20151001_bkp/abc def group report 20151010.html"'; output;
    string = '/abcdef-u01/11111_SASGridGAML_HDprd/xxx/sas_jobs/yyy/data/history/487623847/20151001_bkp/report_20151010.html'; output;
run;

data want;
    set have;
    s = quote(dequote(string));
    keep s;
run;
proc print;run;

Super Contributor
Super Contributor
Posts: 340

Re: including quotation mark for larger string

Thanks a lot everyone -
my challenge was reading last long value which has double quotation mark for some values + and sometime no-quotation mark + space in between - however Patrick solution works absolutely fine,,,

Again thanks a lot,,,
☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 7 replies
  • 260 views
  • 2 likes
  • 5 in conversation