BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
maroulator
Obsidian | Level 7

The attached NCDebt.csv file is the input file for the code in the attached .txt file labelled "Code." The code runs the way that I want it to, but I have the following item that I need to address.

The "Desired Output.txt" file is not generated by the code, however, it holds the structure that I want my Code-generated output to follow; you will notice similarities in the structure of the output generated once you run the code and the structure of the contents in the "Desired Output.txt file." My problem is that I cannot think of a way to write SAS code such that I can add the 'end' line found at the bottom of the Desired Output.txt file. I have commented out the "End='end'" line in the second datastep of my Code (this was my last ditch effort); when I transpose in the proc step, however, I am still stuck with the variable name End, which I don't want. Ideally, I would have a blank in the variable name and retain the value 'end.'

Any takers?

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

Sorry about the put _all_ error. This may come closer, change the name of the file to what you want for your text file.

data _null_;

file 'd:\data\output.txt';

set work.Ncdebt3 end= last;

put _NAME_ col1-col9;

if last then put 'End';

run;

I suspect the unwanted END variable is occurring because of the RETAIN statement when creating NCDebt2. I removed that from the data step then ran the transpose code and the above.

View solution in original post

8 REPLIES 8
ballardw
Super User

Maybe something like;

data _null_;

     file 'Your desired output file name goes here';

     set Ncdebt3 (end= last);

     put _all_;

     if last then put 'End';

run;

maroulator
Obsidian | Level 7


I tried the following; still no go.

data test;

     set Ncdebt3 end= last;

     put _all_;

     if last then put 'end';

run;

PGStats
Opal | Level 21

"Still no go" is not a very good description of what you got!

PG
maroulator
Obsidian | Level 7

PGStats,

My apologies; by "still no go" I meant that I did not achieve my desired result; the Ncdebt3 dataset in my code above remains unchanged. I attach my log if it helps.

PGStats
Opal | Level 21

Why is obs #3 skipped (with firstobs=4)? Why would there be only 6 values present in the multi-valued rows of Desired Output.txt? What would make some rows multi-values and others not, in Desired Output.txt?

PG
maroulator
Obsidian | Level 7

PGStats,

The end-goal of my code is to prepare a .txt file to be fed into a model. The multi- vs single- value rows issue is somewhat arbitrary and is model-dependent, so I don't have a clear-cut rule to give you. Starting at observation 4 is also model-driven. Mind you, however, that none of the two issues that you raise are related to my original question.

I hope this helps.

ballardw
Super User

The code I posted is NOT intended to create a dataset but an output TEXT file which was sort of implied by the use of "desired output text" as the zip file demonstrated. If you want a data set then some more specific description of the output is needed.

ballardw
Super User

Sorry about the put _all_ error. This may come closer, change the name of the file to what you want for your text file.

data _null_;

file 'd:\data\output.txt';

set work.Ncdebt3 end= last;

put _NAME_ col1-col9;

if last then put 'End';

run;

I suspect the unwanted END variable is occurring because of the RETAIN statement when creating NCDebt2. I removed that from the data step then ran the transpose code and the above.

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!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

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
  • 8 replies
  • 648 views
  • 0 likes
  • 3 in conversation