Help using Base SAS procedures

Saving character field from C# app to sas with carriage returns

Accepted Solution Solved
Reply
Super Contributor
Posts: 400
Accepted Solution

Saving character field from C# app to sas with carriage returns

I have a c# app that has a notes section that allows the users to put some text in there and save it.  My issue is that after it is saved and I want to re-display it the carriage return is removed and all the space is removed and everything is stuck together.  What is the best way to handle this?

I have a similar situation creating .sas files and adding carriage returns.

Any help would be appreciated.

Thank you


Accepted Solutions
Solution
‎11-01-2013 01:20 PM
Super User
Super User
Posts: 7,059

Re: Saving character field from C# app to sas with carriage returns

Posted in reply to jerry898969

If you submitted a program like that in a SAS program then the line break would be eliminated.

data _null_;

notes='12345


6789';

put notes= / notes= $hex24. ;

run;

notes=123456789

notes=313233343536373839

But if you put in the hexcodes using literals they will make it in.

data _null_;

notes='12345' || '0d0a'x || '6789';

put notes= / notes= $hex24. ;

run;

notes=12345

6789

notes=31323334350D0A36373839

So in whatever C logic you have to generate the string generate it like the example above instead.

...

set notes='This is a testTHIS IS A TESTtest2TEST3TEST4TEST5TEST6'

       || '0D0A'x

       || 'TEST7'

...

View solution in original post


All Replies
Frequent Contributor
Posts: 121

Re: Saving character field from C# app to sas with carriage returns

Posted in reply to jerry898969

This is a pure C# question, right? So this might not be the best place to ask for help.

This sounds like a .Net property in your Textbox Control. Which user control do you use? Do you use WinForms or WPF?

Look for some properties like "Mulitline" at your control (e.g. TextBox.Multiline Property (System.Windows.Forms))

Super Contributor
Posts: 400

Re: Saving character field from C# app to sas with carriage returns

Posted in reply to AndreasMenrath

Andreas,

Within my C# app it displays correctly when typed in.  When I send the insert or update sql to sas and then I go back to view the text it's one line with the spaces removed.  If I'm saving the text in sas do I have put the carriage returns in when I do the insert or update?

Thank you for your help

Super Contributor
Posts: 253

Re: Saving character field from C# app to sas with carriage returns

Posted in reply to jerry898969

How are you verifying the carriage return is removed?  If you're opening a dataset up in sas (.sas7bdat), it won't display multiline character fields even if they have CRs in them - it will just eat up the space and display as if that character didn't exist.  You'd have to look at the hex value of the sting to see if '0D' was in there somewhere.

If that's not the issue (and it doesn't sound like it's the entire issue), then I agree it's probably a C#/.NET issue.

Super Contributor
Posts: 400

Re: Saving character field from C# app to sas with carriage returns

Posted in reply to snoopy369

Hi Snoopy,


Thank you for the reply.  I see that it is removed when I go into my C# app and open up the form that displays the text.  When I initially entered it, it displayed correctly.  When I saved and closed the app and then opened it up the carriage returns I added were removed and the text is all together.

Thank you

Super User
Super User
Posts: 7,059

Re: Saving character field from C# app to sas with carriage returns

Posted in reply to jerry898969

How is this related to SAS?

Is your application storaging text into variables in a SAS dataset?

What actual SAS code are you using to move the data into and out of SAS?

Super Contributor
Posts: 400

Re: Saving character field from C# app to sas with carriage returns

Hi Tom,

I'm inserting this text into a variable in a sas dataset.  Here is some example code.

proc sql undo_policy = none ;

update tblNotes (cntllev=rec)

set notes='This is a testTHIS IS A TESTtest2TEST3TEST4TEST5TEST6

TEST7'

where id = 9999;

quit ;

Based on Snoopys suggestion I was able to view the hex after I enter the carriage returns in my multiline textbox.   It shows \r\n where my carriage returns are.  I'm losing them some how on the way to sas.

Thank you

Solution
‎11-01-2013 01:20 PM
Super User
Super User
Posts: 7,059

Re: Saving character field from C# app to sas with carriage returns

Posted in reply to jerry898969

If you submitted a program like that in a SAS program then the line break would be eliminated.

data _null_;

notes='12345


6789';

put notes= / notes= $hex24. ;

run;

notes=123456789

notes=313233343536373839

But if you put in the hexcodes using literals they will make it in.

data _null_;

notes='12345' || '0d0a'x || '6789';

put notes= / notes= $hex24. ;

run;

notes=12345

6789

notes=31323334350D0A36373839

So in whatever C logic you have to generate the string generate it like the example above instead.

...

set notes='This is a testTHIS IS A TESTtest2TEST3TEST4TEST5TEST6'

       || '0D0A'x

       || 'TEST7'

...

Super Contributor
Posts: 400

Re: Saving character field from C# app to sas with carriage returns

Hi Tom,


Thank you for the information.  I'm working on it now and will post my results when I finish.

Thank you

Super Contributor
Posts: 400

Re: Saving character field from C# app to sas with carriage returns

Posted in reply to jerry898969

Hi Tom,

Thank you that fixed it.

Thanks again to everyone for their help

Super Contributor
Posts: 400

Re: Saving character field from C# app to sas with carriage returns

Hi Tom,

Sorry to bother you but how would I handle this with an insert statement?  When I try this I get an error for the "||".

proc sql undo_policy = none ;

Insert into tblnotes (cntllev=rec, id, notes)

values(999, 'THIS' || '0d0a'x || 'IS' || '0d0a'x || 'A' || '0d0a'x || 'TEST' || '0d0a'x || 'OF THIS CODE   ' || '0d0a'x || 'TESTING')

;

quit ;

Thanks for the help

Super User
Super User
Posts: 7,059

Re: Saving character field from C# app to sas with carriage returns

Posted in reply to jerry898969

That type of transactional processing is not something I normally attempt to do with SAS.  Why not just insert a blank value and then use the update syntax to put the value into the NOTE variable?  Or you could also just have C write the whole string as hex digits?

values(999,'544849530D0A49530D0A410D0A544553540D0A4F46205448495320434F44452020200D0A54455354494E47'x)

🔒 This topic is solved and locked.

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

Discussion stats
  • 11 replies
  • 388 views
  • 6 likes
  • 4 in conversation