BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
woo
Lapis Lazuli | Level 10 woo
Lapis Lazuli | Level 10

 

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"

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Patrick
Opal | Level 21

@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

7 REPLIES 7
collinelliot
Barite | Level 11

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;

woo
Lapis Lazuli | Level 10 woo
Lapis Lazuli | Level 10

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;

woo
Lapis Lazuli | Level 10 woo
Lapis Lazuli | Level 10

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;

ballardw
Super User

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.

Patrick
Opal | Level 21

@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;

 

Ksharp
Super User
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;

woo
Lapis Lazuli | Level 10 woo
Lapis Lazuli | Level 10
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,,,

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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